import pandas as pd
# 示例数据
data = {
'Date': ['2021-01-01', '2021-01-01', '2021-01-02', '2021-01-02'],
'Variable': ['A', 'B', 'A', 'C'],
'Types':['3','2','5','7'],
'Value': [10, 20, 30, 40]
}
df = pd.DataFrame(data)
#print(df)
# 行转列
df_pivot = df.pivot(index='Date', columns=['Variable','Types'], values='Value')
print(df_pivot)
使用pandas的pivoit函数进行表格数据行转列操作