我有一个这样的数据帧df
。
Number SomeValue SomeOtherValue
10 10 1.0
11 3 1.1
当我使用df.head()
查看数据帧时,我得到
Number SomeValue SomeOtherValue
0 10 10 1.0
1 11 3 1.1
我想把Number
作为索引,所以我做了如下操作:
df.index = df.Number
df = df.drop('Number', 1);
这看起来有点笨拙,那么有没有其他方法可以将列提升为索引呢?
Tags:
您只需使用^{} 方法即可:
这会将列从DataFrame中取出,并将其设置为DataFrame的索引。该方法还允许您快速将多个列设置为索引或检查新索引是否包含重复项。
相关问题 更多 >
编程相关推荐