我有一段我在1年前用木星写的代码,它成功地使用了
dg = pd.read_csv(f10,sep=';')
要读取此数据,请执行以下操作
A;W
83;88,0
64;70,1
94;94,2
今天我得到:
OSError: Initializing from file failed
在中间的某个地方:
C:\Anaconda3\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
964 def _make_engine(self, engine='c'):
965 if engine == 'c':
--> 966 self._engine = CParserWrapper(self.f, **self.options)
967 else:
968 if engine == 'python':
然而,这一点今天起作用了:
with open(f10, newline='') as csvfile:
data = csv.reader(csvfile, delimiter=';')
既然我说了潘达路,有谁知道我该改变什么吗?寻找暗示!
编辑:,我刚刚发现,这也适用于:
with open(f10, newline='') as csvfile:
dg = pd.read_csv(csvfile, delimiter=';')
但这真的有必要吗?
发布于 2017-09-11 13:50:50
我想这个问题来自于newline
,pandas
预计它将是\n
。
您可以直接将缓冲区传递给pd.read_csv()
。
dg = pd.read_csv(open(f10, newline=''), sep=';')
发布于 2017-09-11 13:35:59
试试这个:
import sys
pd.read_csv(f10, sep=';', encoding=sys.getdefaultencoding())
更新:
它也可以是由路径或文件名中带有重音的字符引起的。,所以尝试移动/重命名路径/文件名,使其只有一个ASCII字符,然后再试一次.
https://stackoverflow.com/questions/46164684
复制相似问题