我的代码如下:
import pandas as pd
import numpy as np
df = pd.read_csv("path/to/my/infile.csv")
df = df.sort_values(['distance', 'time'])
df.to_csv("path/to/my/outfile.csv")
这段代码成功读取了一个3GB的csv文件infile.csv,对其进行了排序并在尝试写入outfile.csv时失败,并出现以下错误:
OSError Traceback (most recent call last)
<ipython-input-10-3a5c8279658d> in <module>
----> 1 df.to_csv('/Users/joaomatos/Desktop/cluster22_sorted_training.csv',index=False)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/frame.py in to_csv(self, path_or_buf, sep, na_rep, float_format, columns, header, index, index_label, mode, encoding, compression, quoting, quotechar, line_terminator, chunksize, tupleize_cols, date_format, doublequote, escapechar, decimal)
1743 doublequote=doublequote,
1744 escapechar=escapechar, decimal=decimal)
-> 1745 formatter.save()
1746
1747 if path_or_buf is None:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/io/formats/csvs.py in save(self)
164 encoding=encoding,
165 compression=self.compression)
--> 166 f.write(buf)
167 f.close()
168 for _fh in handles:
OSError: [Errno 22] Invalid argument
我的问题是为什么?
感谢您的帮助
显然,这个问题是由报道了已知的bug导致这里使用以前版本的大熊猫有关。我所要做的就是pip3 install --upgrade pandas
然后重新启动计算机。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句