我有这样一个数据帧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:
您只需使用^{} 方法即可:
这会将列从数据框中取出,并将其设置为数据框的索引。该方法还允许您快速将多个列设置为索引,或检查新索引是否包含重复项
相关问题 更多 >
编程相关推荐