Pandas: Oserror With Accent/special Character In File Path And File Name
Solution 1:
I had a similar problem. It's look like the problem occurs with pandas.read_csv with Python 3.6 in a Windows system.
Python 3.6 change Windows filesystem encoding from "mbcs" to "UTF-8". See Python PEP 529. You can use the command sys.getfilesystemencoding()
to get the current file system encoding
I get two solutions around this:
1.- Use this code to change all the app to works with the prior Python <= 3.5 encoding ("mbcs")
import sys
sys._enablelegacywindowsfsencoding()
2.- Pass a file pointer to the pandas.read_csv
withopen("C:\Users\MyName\Desktop\dumm12\düm1.csv", 'r') as fp:
dum1 = pd.read_csv(fp, sep = ";", decimal = ",", encoding = "utf-8")
You can see this post: pandas.read_csv can't import file with accent mark in path
Solution 2:
I tested the name in creating a fake file 'düm1.csv'.
when I run :
df = pd.read_csv('düm1.csv',sep=';')
I haven't an OSError and the file is open in my Ipython.
Unnamed:0 test1 test2 test3 tes4
0NaN1.02.03.04.01NaNNaNNaNNaNNaN2NaNNaNNaNNaNNaN3NaNNaNNaNNaNNaN4NaNNaNNaNNaNNaN
Have you tried without encoding ? Without accent ?
C.
Solution 3:
The issue hasn't been resolved till now. Wait till a PR. Or try it with Python 2.7 I guess that might work
Post a Comment for "Pandas: Oserror With Accent/special Character In File Path And File Name"