Reputation: 51
I am trying to open a csv file in PyCharm with Pandas, but I get an error message that the csv file is not found? Does it matter where the file is being placed? I tried to open it also with the full path to the file, but it did not work. screen shot
import pandas as pd
df = pd.read_csv("c:\users\user\desktop\jeopardy.csv")
print(df.head())
Upvotes: 0
Views: 3551
Reputation: 54
The file path in the screenshot suggests, that the CSV-file is in the same directory as the .py
-file you are executing to import it. If this is not the case, it will throw the error displayed on your screenshot.
Thus, look for the path to the CSV-file and append it as a string in front of the current file name (don't forget to exchange the backslashes \
for slashes /
when copying the path to Python).
If this does not work, double-check the name of the file and if it is an actual CSV-file.
Upvotes: 1
Reputation: 4855
You need to escape the \
characters in the path name:
df = pd.read_csv("c:\\users\\user\\desktop\\jeopardy.csv")
or use a raw-string by putting r
before the string:
df = pd.read_csv(r"c:\users\user\desktop\jeopardy.csv")
Upvotes: 0