首页 > 解决方案 > Pandas 中的数据框索引转换

问题描述

我想转换以下数据框:

 ID 1234
     type   band    category
  0    A      B       C

至:

ID     type   band   category
1234     A      B      C

其中 ID 是索引列

标签: python-3.xpandasreshapereindex

解决方案


尝试

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

输出:

     ID Type band category
0  1234    A    B        C

推荐阅读