我正在尝试调整当前的两列数据框,目前看起来像这样:
one two
a 12
b 32
c 12
Run Code Online (Sandbox Code Playgroud)
我想透视它,导致两列都不成为索引.我的预期结果是:
a b c
12 32 12
Run Code Online (Sandbox Code Playgroud)
a,b和c是新列.12,32,12是行中的值.
谢谢
使用set_index列"一"进入指数,然后用T移调.
a.set_index('one').T
Run Code Online (Sandbox Code Playgroud)
输出:
one a b c
two 12 32 12
Run Code Online (Sandbox Code Playgroud)
信息:
<class 'pandas.core.frame.DataFrame'>
Index: 1 entries, two to two
Data columns (total 3 columns):
a 1 non-null int64
b 1 non-null int64
c 1 non-null int64
dtypes: int64(3)
memory usage: 28.0+ bytes
None
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3617 次 |
| 最近记录: |