python导入csv报错_python使用read_csv读取CSV文件时报错

Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G手机 双卡双待

4999元包邮

去购买 >

读取csv文件时报错

df = pd.read_csv('c:/Users/NUC/Desktop/成绩.csv' )

Traceback (most recent call last):

File "D:/学习/helloworld/helloworld.py", line 268, in

df = pd.read_csv('c:/Users/NUC/Desktop/成绩.csv' )

File "D:\学习\Python\Python-3.6.5\lib\site-packages\pandas\io\parsers.py", line 678, in parser_f

return _read(filepath_or_buffer, kwds)

File "D:\学习\Python\Python-3.6.5\lib\site-packages\pandas\io\parsers.py", line 440, in _read

parser = TextFileReader(filepath_or_buffer, **kwds)

File "D:\学习\Python\Python-3.6.5\lib\site-packages\pandas\io\parsers.py", line 787, in __init__

self._make_engine(self.engine)

File "D:\学习\Python\Python-3.6.5\lib\site-packages\pandas\io\parsers.py", line 1014, in _make_engine

self._engine = CParserWrapper(self.f, **self.options)

File "D:\学习\Python\Python-3.6.5\lib\site-packages\pandas\io\parsers.py", line 1708, in __init__

self._reader = parsers.TextReader(src, **kwds)

File "pandas\_libs\parsers.pyx", line 384, in pandas._libs.parsers.TextReader.__cinit__

File "pandas\_libs\parsers.pyx", line 697, in pandas._libs.parsers.TextReader._setup_parser_source

OSError: Initializing from file failed

解决:

df = pd.read_csv('c:/Users/NUC/Desktop/成绩.csv', engine='python' )

加上 engine = 'python'

engine的参数有三个 'c','python','python_fwf'

原文链接:https://www.cnblogs.com/zhanshan/p/9370032.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值