将DataFrame保存到csv时遇到错误“ ImportError:无法导入名称'StringIO'”

时间:2019-12-06 20:33:46

标签: python pandas stringio

我有一个熊猫DataFrame output_df,我可以毫无问题地操作或打印它。但是,当我运行output_df.to_csv(output_filename)时,会出现错误:

  File "my_file.py", line 169, in run_attribute_generator
    output_df.to_csv(output_filename)
  File "/usr/local/lib/python3.6/site-packages/pandas/core/generic.py", line 3204, in to_csv
    New Series or DataFrame with updated labels.
  File "/usr/local/lib/python3.6/site-packages/pandas/io/formats/csvs.py", line 17, in <module>
    from pandas.compat import (StringIO, range, zip)
ImportError: cannot import name 'StringIO'

我的熊猫版本是0.25.1

1 个答案:

答案 0 :(得分:1)

here上获得了它

似乎您必须将熊猫版本降级到0.24.2或更低。 希望对您有帮助