Shadman Mahmood Shadman Mahmood - 4 months ago 11
Python Question

Python Cannot find file although the error says it exists

I have been trying to load the files in python but somehow I cant do so? any help or suggestions would be really helpful.

import numpy as np
import pandas as pd
df=pd.read_csv('C:/Users/user/Desktop/Work/a.csv')
type(df)
print df


Error shown:

File C:/Users/user/Desktop/Work/a.csv does not exist

Answer

Seems like you are using windows. Windows directory separator is \ not / try this way:

df=pd.read_csv('C:\\Users\\user\\Desktop\\Work\\a.csv')

or

import os
file_path = os.path.sep.join(["C:", "Users", "user", "Desktop", "Work", "a.csv"])
df = pd.read_csv(file_path)