如何删除 pandas 数据框中的索引名称? [英] How to remove the index name in pandas dataframe?

查看:234
本文介绍了如何删除 pandas 数据框中的索引名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据框中,我在索引列的名称上写了一个 2。
当我检查列名称时,它没有显示在此处,但作为
df.columns给出了它的输出。我不知道如何从数据集中删除那个 2。

In my dataframe, I get a '2' written over my index column's name. when I check for the columns name it doesn't show up there but as df.columns give this as output. I don't know how to remove that '2' from my dataset.

我尝试删除索引名称,但并没有解决我的问题。

I have tried removing index name but it hasn't solved my issue.

 df.columns ==> Output
     Index(['name', 'census 1981', 'census 1998', 'estimate 2000',
       'calculation 2010', 'annual growth', 'latitude', 'longitude',
       'parent division', 'name variants'],
      dtype='object', name=2)

我只希望索引的名称...不包括在其上乱写的'2'

I expect only the index with its name...not including that freaking '2' over it

推荐答案

您需要更改列名,而不是索引!

df.columns.name=''

要理解的示例:

df=pd.DataFrame()
df['a']=[1,2,3]
df.columns.name='name column'
df.index.name='name index'
df

输出:

name column  a
name index  
0            1
1            2
2            3

现在在做:

df.columns.name=''

输出:

           a
name index  
0          1
1          2
2          3

这篇关于如何删除 pandas 数据框中的索引名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆