python pandas DataFrame 转置
python pandas DataFrame 转置import pandas as pddf1 = pd.DataFrame({'日期': ['2021-7-2', '2021-8-2', '2021-9-2', '2021-10-2'],'A': [1, 2, 3, 4],'B': [5, 6, 7, 8],'C': [9, 10, 11, 12],'D': [13, 14, 15, 16]
·
python pandas DataFrame 转置
import pandas as pd
df1 = pd.DataFrame(
{
'日期': ['2021-7-2', '2021-8-2', '2021-9-2', '2021-10-2'],
'A': [1, 2, 3, 4],
'B': [5, 6, 7, 8],
'C': [9, 10, 11, 12],
'D': [13, 14, 15, 16]
},
index=[0, 1, 2, 3])
print(df1)
日期 A B C D
0 2021-7-2 1 5 9 13
1 2021-8-2 2 6 10 14
2 2021-9-2 3 7 11 15
3 2021-10-2 4 8 12 16
df2 = df1.T # 转置
print(df2)
0 1 2 3
日期 2021-7-2 2021-8-2 2021-9-2 2021-10-2
A 1 2 3 4
B 5 6 7 8
C 9 10 11 12
D 13 14 15 16
更多推荐
已为社区贡献12条内容
所有评论(0)