我想转换此数据框(请注意“ABC”是索引名称):
t1 t2 t3
ABC
gp 7 11 26
fp 6 14 23
pm 3 -1 7
wm 2 -2 9
到此数据框:
s1 tx gp fp pm wm
0 ABC t1 7 6 3 2
1 ABC t2 11 14 -1 -2
2 ABC t3 26 23 7 9
执行此功能的最佳方式是什么?
最佳答案
这个怎么样:
df = df.T
df.reset_index(inplace=True)
df.rename(columns={"index":"tx"}, inplace=True)
df["s1"] = "ABC"
关于python - 重新排列Python数据框索引和列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52155125/