Skip to content
Advertisement

Save DataFrame to csv encounters error “ImportError: cannot import name ‘StringIO'”

I have a pandas DataFrame output_df that I can manipulate or print without problems. However, when I run output_df.to_csv(output_filename), it gives an error:

  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'

My pandas version is 0.25.1

Advertisement

Answer

got it from here

It seems that you have to downgrade your pandas version to 0.24.2 or lower. Hope it helps

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement