Python: FileNotFound Error. No such file or directory - python

I'm writing a program in which Python is unable to read my file despite of me posting the absolute file path with Pandas. The weirdest part is that this program has worked before but it just doesn't now, and I can't get to the bottom of why. Here is the program and error:
import pandas as pd
df = pd.read_csv(r"C:\Users\user\Desktop\Small_businesses1",encoding='latin1')
Error:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\user\\Desktop\\Small_businesses1'
The file is for sure at that very location, I copy pasted the location! Any fixes will be greatly appreciated

it seems that you have omitted the file type suffix try
df = pd.read_csv(r"C:\Users\user\Desktop\Small_businesses1.csv",encoding='latin1')

Related

Having issues reading a .csv file present in a directory

I have a following path defined where I have
label_csv_file = r"C:/Users/username/Downloads/Personal Stuff/Python Directory files/Scripts/CSV Copy Scripts/label.csv"
I was trying to read the csv using pandas,
import pandas as pd
labelpd = pd.read_csv(label_csv_file)
I get the following error:
handle = open(
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/username/Downloads/Personal Stuff/Python Directory files/Scripts/CSV Copy Scripts/label.csv', but the file is clearly there
I blacked out my name, instead of username my name is in the path, so I don't understand why I am having the issue, I have changed the label.csv to be just label as well. Its not just pandas, I was having issues opening with even with
open(label_csv_file, 'rb'),
where the label_csv_file path had been set, what is the issue here?
I have tried changing the file name to just label as it is already a .csv file that does not work either, I have changed the file path to just say /label, that doesn't work either

FileNotFoundError: [Errno 2] File b'filepath.csv' does not exist:

I created a df to read a csv in my jupyter notebook library but for some reason the i'm getting an error like this:
FileNotFoundError: [Errno 2] File b'file path/filename.csv' does not exist: b'/file path/filename.csv'
My code is this:
df_csv = pd.read_csv('../file_path/file_name.csv', low_memory=False)
I believe I am using the absolute path to this file...I also checked the directory to confirm I was using the correct path.
import os
print(os.path.abspath('file_name.csv'))
and the output was:
/YXRwLW5vdGVib29rLW5pbmd1eWVuLXNlc3Npb24teGJ1YQ==/file_path/file_name.csv
Is that not the same as '../file_path/file_name.csv'? Would appreciate any troubleshooting tips...
I am not sure why this worked but instead of using the absolute path I used the relative path and just read the file name...A bit concerned with this method since I'd rather be explicit

Python: "../DATA/file.csv" no longer working for file opening

Since a while, I have been using the short syntax ('../DAT/file.csv') to get to files under DATA folder. Since this morning, it is not working anymore and I am getting the following error:
FileNotFoundError: [Errno 2] No such file or directory: '../DATA/file.csv'
Any thoughts? Code I am using is below:
Thanks in advance,
df = pd.read_csv('../DATA/moviereviews.csv')
Check if your current directory is the one you expect it to be (i.e. the one that is beside the DATA directory). You can use the following to do so:
import os
print(os.getcwd())
Check that DATA/moviereviews.csv actually exists.

pandas cannot read csv in same directory

i am having this issue since like 2 months, it didnt bother me at first but now that im trying to import a file with pd or even a normal txt file with open() it gives me this Exception:
File "C:\Users\lcc_zarkos\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\common.py", line 642, in get_handle
handle = open(
FileNotFoundError: [Errno 2] No such file or directory: 'marketing.xlsx'
if i use the full path it just runs normally.
people would say "just use full path then" but this is a really bad solution when it comes to using this program on multiple devices with different paths or stuff like that
so i hope you have any solutions.
here is the code:
import pandas as pd
df = pd.read_csv('marketing.xlsx')
image:
vscode
folder
edit:
it has none to do with the code itself but more like windows or my pc
FileNotFoundError means that the file path you've given to pandas point to an non existing file.
In your case this can be caused by:
you haven't put your file in the current working directory of your script
you have a typo in your file name
In both case, I would print the file path, and check the location using a file browser, you will find your mistake:
print(os.path.join(os.getcwd(), 'marketing.xlsx'))
i see a spaces in the file name there. I tried on mac, and it works very well.
['main.py', 'marketing .xlsx', 'requirements.txt']

import csv into pandas dataframe

I am facing difficulty importing a csv file to python from my desktop. It seems that the file or the location is not being recognized while reading.
Have tried several different methods to import, but every time it gives the same error:
IOError: [Errno 2] No such file or directory: '/Users/uditasingh/Desktop/Analysis/monthly_visits.csv'
for the code:
import csv
cr = csv.reader(open("/Users/uditasingh/Desktop/Analysis/monthly_visits.csv","rb"))
I have obtained the path of the csv file from the file 'properties'.
Don't understand what seems to be going wrong.
Please help!
Thanks
My bet is that it searches for the Users directory in the code's working dir and obviously can't find it. Try to use the full path, ie 'C:/Users/......`.
try to write
cr = csv.reader(open("\Users\uditasingh\Desktop\Analysis....))

Categories