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

后端 未结 2 1662
-上瘾入骨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
    

提交回复
热议问题