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

前端 未结 1 1977
名媛妹妹
名媛妹妹 2021-01-03 08:44

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

AttributeError                            Traceback (most recent cal         


        
相关标签:
1条回答
  • 2021-01-03 09:38

    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
    
    0 讨论(0)
提交回复
热议问题