Exporting CSV shows ImportError: cannot import name 'CompressionOptions' from 'pandas._typing'

Viewed 12944

When attempting to export to CSV the error below arises:

-I've tried updating pandas and then reverting to an older version with no luck.

~\Anaconda4\lib\site-packages\pandas\core\generic.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, date_format, doublequote, escapechar, decimal, errors)
   3143         Examples
   3144         --------
-> 3145         >>> df = pd.DataFrame(dict(name=['Raphael', 'Donatello'],
   3146         ...                   mask=['red', 'purple'],
   3147         ...                   weapon=['sai', 'bo staff']))

~\Anaconda4\lib\site-packages\pandas\io\formats\csvs.py in <module>
     10 
     11 from pandas._libs import writers as libwriters
---> 12 from pandas._typing import (
     13     CompressionOptions,
     14     FilePathOrBuffer,

ImportError: cannot import name 'CompressionOptions' from 'pandas._typing' (C:\Users\Bob\Anaconda4\lib\site-packages\pandas\_typing.py)
2 Answers

It seems that the problem is with the latest updates of the Pandas package (Release version 1.2.0 and 1.2.1).

To solve the problem, you can downgrade the version to "1.1.5" (The latest update on the 1.1 release). For doing so, I recommend you remove the package first and reinstall it again.

pip uninstall pandas
pip install pandas==1.1.5

I had the same issue and could resolve it with the above simple solution.

Update your pandas lib

pip install pandas --upgrade
Related