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).
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.