Remove index name in pandas

家住魔仙堡 提交于 2019-11-27 07:32:10

Use del df.index.name

In [16]: df
Out[16]:
         Column 1
foo
Apples          1
Oranges         2
Puppies         3
Ducks           4

In [17]: del df.index.name

In [18]: df
Out[18]:
         Column 1
Apples          1
Oranges         2
Puppies         3
Ducks           4

Alternatively you can just assign None to the index.name attribute:

In [125]:

df.index.name = None
df
Out[125]:
         Column 1

Apples          1
Oranges         2
Puppies         3
Ducks           4
jezrael

From version 0.18.0 you can use rename_axis:

print df
         Column 1
foo              
Apples          1
Oranges         2
Puppies         3
Ducks           4

print df.index.name
foo


print df.rename_axis(None)
         Column 1
Apples          1
Oranges         2
Puppies         3
Ducks           4

print df.rename_axis(None).index.name
None

# To modify the DataFrame itself:
df.rename_axis(None, inplace=True)
print df.index.name
None

You can delete index name by using the following line of code:

del df.index.name 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!