【问题标题】:Data frame index transformation in PandasPandas 中的数据框索引转换
【发布时间】:2020-10-16 04:47:32
【问题描述】:

我要转换以下数据框:

 ID 1234
     type   band    category
  0    A      B       C

到:

ID     type   band   category
1234     A      B      C

其中 ID 是索引列

【问题讨论】:

    标签: python-3.x pandas reshape reindex


    【解决方案1】:

    试试

    df.stack(0).reset_index().drop('level_0', axis=1)
    

    输出:

         ID Type band category
    0  1234    A    B        C
    

    【讨论】:

      猜你喜欢
      • 2016-03-28
      • 2020-07-11
      • 2016-04-26
      • 2018-03-22
      • 2021-10-08
      • 1970-01-01
      • 2018-02-01
      • 2020-06-02
      • 1970-01-01
      相关资源
      最近更新 更多