4

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?

3
  • I never heard of that attribute in the first place. Where did you find out about it and what is it supposed to do? Commented Feb 14, 2017 at 19:31
  • 1
    Maybe pandas.formats.format.header_style? Commented Feb 14, 2017 at 19:33
  • @BrenBarn I have no idea where I heard about it but I use it to remove the formatting before writing dataframes to xlsx worksheets with xlsxwriter. Commented Feb 14, 2017 at 19:36

2 Answers 2

11

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
Sign up to request clarification or add additional context in comments.

5 Comments

Yep that is what it is. Don't you just love it when stuff gets moved around.
you are using a non public property. since this is not part of any guarantee you should following the changes very closely.
I'm sorry I don't understand what you mean. Could you please rephrase and/or expand on this?
@measure_theory Correct, I updated the answer, thanks.
I hope the panda devs will change it at least twice so I have to find it again every time I want to make a new excel dumper
0

More recent versions of pandas do not use pandas.core.format. You can find examples in this link.

import pandas as pd
df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
df.style.to_html(df, precision=2, caption="My table")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.