【问题标题】:Convert a column to an index in pandas将列转换为熊猫中的索引
【发布时间】:2022-12-04 11:19:28
【问题描述】:

I have a DataFrame df like this.

Number SomeValue SomeOtherValue
  10    10        1.0
  11     3        1.1

when I look at the data frame using df.head(), I get this

  Number SomeValue SomeOtherValue
0  10    10        1.0
1  11     3        1.1

I would like Number to be my index, so I do something like this:

df.index = df.Number
df = df.drop(\'Number\', 1);

This seems a bit clumsy, so is there another way of promoting a column to an index?

    标签: python pandas dataframe


    【解决方案1】:
    猜你喜欢
    • 2019-03-26
    • 2021-12-20
    • 1970-01-01
    • 2021-08-28
    • 2013-12-26
    相关资源
    最近更新 更多