当在用Python的Pandas库进行读取csv文件,出现了以下错误时:
Traceback (most recent call last):
File "D:/Pycharm/PythonSpider/HelloWorld.py", line 18, in <module>
shangHai = pd.read_csv('链家上海租房信息.csv')
File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 678, in parser_f
return _read(filepath_or_buffer, kwds)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 440, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 787, in __init__
self._make_engine(self.engine)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 1014, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\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
应该就是因为你的文件名是中文而导致没有办法解析:
比如:
f = pd.read_csv('要打开的文件.csv') 只需要这样改就可以了:
f = open('要打开的文件.csv','r', encoding='UTF-8') file = pd.read_csv(f) print(file) 热门文章
- 武汉宠物领养中心官网地址电话(武汉宠物猫领养中心)
- 3月21日最新机场订阅 | 21.6M/S|2025年Clash/Shadowrocket/SSR/V2ray免费节点地址链接分享
- 4月1日最新机场订阅 | 19.8M/S|2025年SSR/Clash/Shadowrocket/V2ray免费节点地址链接分享
- Springboot之请求映射
- 3月8日最新机场订阅 | 21.6M/S|2025年SSR/V2ray/Shadowrocket/Clash免费节点地址链接分享
- 宠物猫疫苗要多少钱一次(宠物猫疫苗多少钱打一次)
- C ++中的最低票价
- 3月5日最新机场订阅 | 20.2M/S|2025年Shadowrocket/Clash/SSR/V2ray免费节点地址链接分享
- 动物医院资质级别有哪些要求和标准 动物医院资质级别有哪些要求和标准呢
- 宠物打疫苗后多久可以驱虫(宠物打完疫苗多久可以吃饭)