How to Upload a File Using Pandas in Python - python

I'm having a problem uploading a file ( the file is called "kickstarter1.csv" it is in the image that I attached) using Pandas in python. In the bottom of the picture I attached, it is saying that the file does not exist. I found out a way to view the full path of my file which is located at the bottom of the finder window ( it is in the image I attached). How do I code the full path into my pandas code? I'm using Anaconda Navigator ( I'm not sure if that is relevant).

provide the complete path of your CSV file while reading it through pandas as
name_you_want = pd.read_csv('path/file_name.csv')
or go to the specific folder using cd command on notebook and then read the CSV file.

Related

How to import python files in Google Colab

So I have been trying to make this file compatible to Google Colab but I'm not able to find any way to do it.
[]
EfficientDet-DeepSORT-Tracker is the main folder of this entire package
This picture is from one of the files placed alongside backbone.py
How to fix the fact that the file isn't able to detect backbone.py?
EDIT for more context: I shared the errors I found when trying to run waymo_open_dataset.py which isn't able to detect the other .py files alongside it.
According to this past question you could import 'filename' of the filename.py. So in the main.py file you are trying to run in colab, then import the required files in the main.py file.

Jupyter Notebook/Pandas not reading excel file after moving ipynb

I'm working on automating some reporting for work which starts off with a pd.read_excel method. It worked fine and I moved on with the rest of my code. When I was done, I had a few ipynb files on my desktop and moved them into a folder called "Python". After doing so, I'm getting a "No such file or directory" error when rerunning the code. The file is in a folder called "Reporting". I can leave them on the desktop for now, but typically have everything organized in folders to avoid clutter. What do I need to do to get my code to continue read in the excel files?
RawData=pd.read_excel("Reporting/LS_Questions.xlsx",skiprows=2)
Try using an absolute path rather than a relative path.
Right now your path assumes that the file is within the same directory as the notebook.
you can either:
use a full path a.i - "C:\User{user_name}\Desktop\LS_Questions.xlsx"
Move the CSV/XL file to the directory of the notebook.

VScode isn't creating a file with python

I'm using this code to create a file with "AAA" written in it. It's working in the regular python IDLE but isn't working in VScode.
with open("another.txt","w") as myfile:
myfile.write("AAA")
If no error is reported, then the file is successfully created somewhere. As you are using a relative path the file is probably saved to current working directory.
You can find it either via the path displayed in the terminal you are using, or in your Python code:
from pathlib import Path
print(Path.cwd())

Using not uploaded file in jupyter notebook

Is it possible to use not uploaded files for example images in your jupyter notebook or is there a script for uploading files into your jupyter notebook? I have done some research but didn't find anything.
For sure! Like an usual python script. Let's say you want to open a file named "file.txt" and read its content.
with open("the/path/of/file.txt", "r") as file:
text = file.read()
Now an image using cv2 named picture.jpg
image = cv2.imread("the/path/of/the/image/picture.png)

Cant read csv files using pandas in Visual Code

Python : 3.5
IDE : Visual code
Platform : win 10 64 bit
First i created a virtual env _kerasVenv and then activated the env and then installed pandas using pip.
This is my directory structure:
I added a python script in Exercise files folder where I am trying to read .csv file using pandas
test= pd.read_csv('test.csv', encoding='utf-8')
.csv file and python script are in the same folder so wrong path is not the issue.But i am getting below error:
Unable to open 'parsers.pyx': Unable to read file (Error: File not found (c:\users\anubhav.jhalani\downloads\ex_files_building_deep_learning_apps\pandas\_libs\parsers.pyx)).
Can someone explain why python is looking for pandas in c:\users\anubhav.jhalani\downloads\ex_files_building_deep_learning_apps folder and why parsers.pyx file does not exist in original pandas folder which are in _kerasVenv folder?
How can i get rid of this error?
Update: I found out while hovering on import pandas as pd statement that it is looking for pandas module in c:\users\anubhav.jhalani\downloads\ex_files_building_deep_learning_apps . Why it is happening?
I think it is easier to always give the total file path.
Instead of:
test= pd.read_csv('test.csv', encoding='utf-8')
try to use:
test = pd.read_csv('C:/users/anubhav.jhalani/downloads/ex_files_building_deep_learning_apps/test.csv', endcoding='utf-8')
this should help, you can also have a look here, what syntax you need to write it:
Windows path in Python
You can also get the full path in your windows explorer, if you are unsure where it is saved.
In my case it also wasn't able to find the file even in the same directory and with the complete path. I figured it out that this issue was happening only in my VSCode editor and when I opened the same notebook in jupyter lab it was perfectly working. So then I tried one thing that make it work for me in VSCode as well was that I put my file in the directory other than "C". For example I put my file in the "D" directory and in VSCode it becomes able to work fine.

Categories

Resources