I'm trying to load a .csv
file using the pd.read_csv()
function when I get an error despite the file path being correct and using raw strings.
import pandas as pd
df = pd.read_csv('C:\\Users\\user\\Desktop\\datafile.csv')
df = pd.read_csv(r'C:\Users\user\Desktop\datafile.csv')
df = pd.read_csv('C:/Users/user/Desktop/datafile.csv')
all gives the error below:
FileNotFoundError: File b'\xe2\x80\xaaC:/Users/user/Desktop/tutorial.csv' (or the relevant path) does not exist.
Only when i copy the file into the working directory will it load correct.
Is anyone aware of what might be causing the error?
I had previously loaded other datasets with full filepaths without any problems and I'm currently only encountering issues since I've re-installed my python (via Anaconda package installer).
Edit:
I've found the issue that was causing the problem.
When I was copying the filepath over from the file properties window, I unwittingly copied another character that seems invisible.
Assigning that copied string
also gives an unicode error.
Deleting that invisible character made any of above code work.
There is an another problem on how to delete the characters that seem invisible.
My solution is copying the filepath from the file windows instead of the property windows.
That is no problem except that you should fulfill the filepath.
I know following is a silly mistake but it could be the problem with your file.
I've renamed the file manually from
adfa123
toabc.csv
. The extension of the file was hidden, after renaming, Actual File name becameabc.csv.csv
. I've then removed the extra.csv
from the name and everything was fine.Hope it could help anyone else.
I was trying to read the
csv
file from the folder that was in my 'c:\'drive but, it raises the error ofescape,type error, unicode
......as such but this code works just take an variable then add r to read it.