Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)
like image 317
Sloppy Joe Avatar asked Oct 19 '25 03:10

Sloppy Joe


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.

like image 152
Mahdi Avatar answered Oct 22 '25 04:10

Mahdi


Update your pandas lib

pip install pandas --upgrade
like image 45
Shashank kumar Avatar answered Oct 22 '25 05:10

Shashank kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!