我有以下数据帧:
index PUBLICO CLASSIFICACAO_PUBLICO
0 19 143643 1
1 34 111879 2
2 31 50382 3
3 9 49204 4
4 32 37541 5
5 4 36095 6
我需要将索引名列转换为索引列。你知道吗
例如:
index PUBLICO CLASSIFICACAO_PUBLICO
19 143643 1
34 111879 2
31 50382 3
9 49204 4
32 37541 5
4 36095 6
我试着用df.set_index('index')
,但没用。你知道吗
以前名为index
的列是DataFrame的索引列,但我使用了reset_index()
;现在我需要做相反的操作。你知道吗
方法
set_index
不适用。因此您必须重新分配数据帧,或者传递选项inplace = True
:或者
见http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html
您可以这样尝试:
这会将
index
列设置为数据帧中的索引,并且index
列也会保留在数据帧中。然后,你就可以放下那一栏。你知道吗相关问题 更多 >
编程相关推荐