Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas raising: AttributeError: module 'pandas.core' has no attribute 'format'

Tags:

python

pandas

I get the following error when running pd.core.format.header_style = None:

AttributeError                            Traceback (most recent call last)
<ipython-input-25-fb23b66754fa> in <module>()
     11 # df1.to_excel(writer, sheet_name='Sheet1')
     12 
---> 13 pd.core.format.header_style = None

AttributeError: module 'pandas.core' has no attribute 'format'

Does anybody know where format has moved to?

like image 245
James Draper Avatar asked Oct 26 '25 08:10

James Draper


1 Answers

You're now looking for

pd.formats.format.header_style = None

I believe, as of version 0.18.1. See the issue CLN & REORG core/common.py #12503.


Edit (version >= 0.20)

As mentioned by Jeff, this is not a public property and so is prone to move around. Now it is found in pandas.io.formats.excel, which you'll have to import.

If you wanted to handle accessing it from different versions thus far (again, susceptible to change), an adaptation from this incompatibility issue might look something like

import packaging.version
import pandas
import pandas.io.formats.excel

def get_format_module():
    version = packaging.version.parse(pandas.__version__)
    if version < packaging.version.parse('0.18'):
        return pandas.core.format
    elif version < packaging.version.parse('0.20'):
        return pandas.formats.format
    else:
        return pandas.io.formats.excel.ExcelFormatter
like image 193
miradulo Avatar answered Oct 28 '25 21:10

miradulo



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!