python - OSError:在 Pandas 中的 csv 上从文件初始化失败
问题描述
到目前为止pandas
,我没有任何问题地阅读了我所有的 CSV 文件,但是现在似乎有问题..
做的时候:
df = pd.read_csv(r'path to file', sep=';')
我得到:
() 中的 OSError Traceback (最近一次调用最后一次) ----> 1 df = pd.read_csv(r'path Übersicht\Input\test\test.csv', sep=';')
c:\program files\python36\lib\site-packages\pandas\io\parsers.py in parser_f(filepath_or_buffer,sep,delimiter,header,names,index_col,usecols,squeeze,prefix,mangle_dupe_cols,dtype,engine,converters, true_values,false_values,skipinitialspace,skirows,nrows,na_values,keep_default_na,na_filter,详细,skip_blank_lines,parse_dates,infer_datetime_format,keep_date_col,date_parser,dayfirst,迭代器,块大小,压缩,数千,十进制,lineterminator,quotechar,quoting,escapechar,comment,编码、方言、tupleize_cols、error_bad_lines、warn_bad_lines、skipfooter、skip_footer、双引号、delim_whitespace、as_recarray、compact_ints、use_unsigned、low_memory、buffer_lines、memory_map、float_precision) 703 skip_blank_lines=skip_blank_lines) 704 -->705 返回_read(filepath_or_buffer, kwds) 706 707 parser_f。名字=名字
c:\program files\python36\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds) 443 444 # 创建解析器。--> 445 parser = TextFileReader(filepath_or_buffer, **kwds) 446 447 如果是块大小或迭代器:
c:\program files\python36\lib\site-packages\pandas\io\parsers.py in init (self, f, engine, **kwds) 812 self.options['has_index_names'] = kwds['has_index_names'] 813 --> 814 self._make_engine(self.engine) 815 816 def close(self):
c:\program files\python36\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine) 1043 def _make_engine(self, engine='c'): 1044 if engine == 'c': -> 1045 self._engine = CParserWrapper(self.f, **self.options) 1046 else: 1047 if engine == 'python':
c:\program files\python36\lib\site-packages\pandas\io\parsers.py in init (self, src, **kwds) 1682 kwds['allow_leading_cols'] = self.index_col is not False 1683 -> 1684 self._reader = parsers.TextReader(src, **kwds) 1685 1686 # XXX
pandas._libs.parsers.TextReader 中的 pandas_libs\parsers.pyx。初始化()
pandas_libs\parsers.pyx 在 pandas._libs.parsers.TextReader._setup_parser_source()
OSError:从文件初始化失败
可以毫无问题地访问同一文件夹中属于 XLS 文件的其他文件。
像这样使用 Python 库时:
import csv
file = csv.reader(open(r'pathtofile'))
for row in file:
print(row)
break
df = pd.read_csv(file, sep=';')
正在加载文件并打印第一行。但是我得到:
ValueError:文件路径或缓冲区对象类型无效:
可能是因为我不能用read_csv
这种方式...
如何让第一个pandas
功能发挥作用?csv 不包含除德语以外的任何特殊字符。文件大小为 10MB。
解决方案
import pandas as pd
pd.read_csv("your_file.txt", engine='python')
尝试这个。它完全适合我。
- 来源: http: //kkckc.tistory.com/187
推荐阅读
- c# - 在 ASP.NET WebApi 2 中测试 OWIN 中间件:如何设置 cookie?
- ios - 如果以编程方式添加,UISwitch 不会响应操作
- firebase - 如何在 Firestore 和 Android 中选择位置?
- amazon-web-services - AWS Athena 中的第一个查询需要很长时间才能得到响应
- bash - 如何使用一个 bash 脚本运行多个独立作业?
- python - matplotlib:绘制一条迭代数据框行的线
- javascript - 如何使用javascript在任务管理器中打开应用程序
- excel - 将功能添加到 Excel,而不是通过加载项
- c# - 如何使用 Hooks 唯一标识应用程序中的字段或控件?
- php - PHP数组与数组(二维数组?)到csv