反转pandas DataFrame中的索引和列 [英] Invert index and columns in a pandas DataFrame
本文介绍了反转pandas DataFrame中的索引和列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的熊猫DataFrame只有一行:
I have a pandas DataFrame with a single row:
10 20 30 70
data1: 2.3 5 6 7
我想重新索引框架,以使列值(10、20、30、70)成为索引值,而数据成为列:
I want to reindex the frame so that the column values (10, 20, 30, 70) become index values and the data becomes the column:
data1:
10 2.3
20 5.0
30 6.0
70 7.0
我该如何实现?
推荐答案
您正在寻找 T
)方法:
You're looking for the transpose (T
) method:
In [11]: df
Out[11]:
10 20 30 70
data1: 2.3 5 6 7
In [12]: df.T
Out[12]:
data1:
10 2.3
20 5.0
30 6.0
70 7.0
这篇关于反转pandas DataFrame中的索引和列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文