Pandas - remove the label of the column index

前端 未结 5 2178
遇见更好的自我
遇见更好的自我 2021-02-12 22:47

I have a dataframe as follows:

PLEASE_REMOVE  2013  2014  2015
 THIS_IS_EASY
-------------------------------
          Bob     0     3     4
         Mary     2          


        
相关标签:
5条回答
  • 2021-02-12 23:08

    In Pandas 1.0.3 the following works:

    df.columns.name = None
    

    The 'accepted answer' above, del df.columns.name, leads to: 'AttributeError: can't delete attribute'

    0 讨论(0)
  • 2021-02-12 23:15

    In Pandas 1.0.3 I have used the following :

    df.rename_axis(None, axis = 1)
    
    0 讨论(0)
  • 2021-02-12 23:18

    New answer for pandas 1.x, submitted by Ian Logie

    df.columns.name = None
    

     

    Old Answer from Oct 2018

    Simply delete the name of the columns:

    del df.columns.name
    

    Also, note that df.index.names = [''] is not quite the same as del df.index.name.

    0 讨论(0)
  • 2021-02-12 23:21

    Like this:

    df = df.rename_axis(None)
    

    This will get rid of everything on the top left. you can also do it in place: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.rename_axis.html

    0 讨论(0)
  • 2021-02-12 23:32

    columns.name will not work since poster want to remove the index name

    df.index.name = None
    
    0 讨论(0)
提交回复
热议问题