Pandas 中的数据框索引转换
Data frame index transformation in Pandas
我想转换以下数据框:
ID 1234
type band category
0 A B C
至:
ID type band category
1234 A B C
其中ID为索引列
尝试
df.stack(0).reset_index().drop('level_0', axis=1)
输出:
ID Type band category
0 1234 A B C
我想转换以下数据框:
ID 1234
type band category
0 A B C
至:
ID type band category
1234 A B C
其中ID为索引列
尝试
df.stack(0).reset_index().drop('level_0', axis=1)
输出:
ID Type band category
0 1234 A B C