removing the name of a pandas dataframe index after appending a total row to a dataframe

后端 未结 2 1642
-上瘾入骨i
-上瘾入骨i 2021-01-12 00:06

I have calculated a series of totals tips by day of a week and appended it to the bottom of totalspt dataframe.

I have set the index.name f

相关标签:
2条回答
  • 2021-01-12 00:36

    That's the columns' name.

    In [11]: df = pd.DataFrame([[1, 2]], columns=['A', 'B'])
    
    In [12]: df
    Out[12]:
       A  B
    0  1  2
    
    In [13]: df.columns.name = 'XX'
    
    In [14]: df
    Out[14]:
    XX  A  B
    0   1  2
    

    You can set it to None to clear it.

    In [15]: df.columns.name = None
    
    In [16]: df
    Out[16]:
       A  B
    0  1  2
    

    An alternative, if you wanted to keep it, is to give the index a name:

    In [21]: df.columns.name = "XX"
    
    In [22]: df.index.name = "index"
    
    In [23]: df
    Out[23]:
    XX     A  B
    index
    0      1  2
    
    0 讨论(0)
  • 2021-01-12 00:38

    You can use rename_axis. Since 0.17.0

    In [3939]: df
    Out[3939]:
    XX  A  B
    0   1  2
    
    In [3940]: df.rename_axis(None, axis=1)
    Out[3940]:
       A  B
    0  1  2
    
    In [3942]: df = df.rename_axis(None, axis=1)
    
    In [3943]: df
    Out[3943]:
       A  B
    0  1  2
    
    0 讨论(0)
提交回复
热议问题