+ 5
Problem in Python pandas read csv
Here is My code - import pandas as pd df = pd.read_csv(āC:\users\user\Desktop\Inanā) print(df.head()) However I keep getting unicode error. I put r,changed slashes,used decode utf,encoding utf,but none are working. They either show unicode error,or say file not found. What am I missing? Arenāt I supposed to put the file path of the csv file in my device inside the bracket? How do I make it work? Like I said,using double backlash,using different combination of slash,putting ārā in front of C DID NOT WORK
25 Answers
+ 4
I saved the file as āDeaths.csvā So when I put the filepath,I was supposed to write āDeaths.csv.csvā But instead I put only one csv. So I just changed the name to Deaths and put a csv in the code,and it was fixed.
And I needed to put the r in front. It looks like this now -
df = pd.read_csv(rāC:\Users\User\Desktop\Inan\deaths.csvā)
As this is an almost irreplicable and a silly mistake,I didnāt want to post the answer. But I did it anyways,just in case anyone might find it helpful XD
+ 6
Have you tried double backslashes?
pd.read.csv("C:\\users\\user\\Desktop\\Inan")
+ 4
Check the following things:
1) Is your file in the directory it is supposed to be?
2) Did you type the file name correctly in the Python script?
3) Is Python able to find the directory in which your file is?
4) Is the file closed (and not open in another program)?
+ 3
Ahnaf Inan you want to read a certain file, don't you?
So your path should be something like
r"MyFolder\mydata.csv"
+ 3
Ahnaf Inan
no that mistake was not silly.
It happens sometimes.
To post the mistake upgrades this post and might help others.
+ 2
import pandas as pd
df = pd.read.csv(rāC:\users\user\Desktop\Inanā)
print(df.head())
also os.path can help.
+ 2
My bad,that was a typo. I did run it with _csv,not .csv
+ 2
You only pass the string with the directory? Where is the file name???
+ 2
6. is content csv?
+ 2
Oma Falk if youāre talking about what the error message I got before was,it was the unicode error,and the file not found error.
The file not found error was fixed by properly writing the filename.csv. As for the unicode error,putting the r in front of C:\ fixed it by turning into a raw string
+ 1
could u send a hardcooy of error message please?
+ 1
maybe in your time line (feed)
+ 1
5) Are you running Python in an IDE or in shell/ command line...?
+ 1
Ahnaf Inan I agree with Oma Falk: It ain't silly, and we all run in problems like that from time to time. š
Thanks, you came back to this thread to share your solution!
0
moment...
u know it is pd.read_csv?
0
ok... next try
import pandas as pd
df = pd.read.csv(rāC:\users\user\Desktop\Inanā, encoding = "utf-8" )
print(df.head())
0
did the encoding utf too
And also the decode utf
as well as engine=python
0
@ Lisa sorry...I didnāt get it...
How do I put the file name?
0
Lisa I think Iām dumb as heck. Anyways,I did it the way you said and it said file not found :(
0
Just change the path of .csv file