print(df2)
test_data = pd.pivot(data=df2 # 待转换df
, index=['main_customer_code1','product_code1']
# df交叉后行
, columns='data_date1' # df交叉后的列
, values='today_amount1' # df交叉后数据(不发生聚合)
)
test_data.reset_index(inplace=True)
print(test_data)
panas 行转列
最新推荐文章于 2024-09-14 22:18:26 发布
该篇文章介绍了如何使用Python的pandas库中的pivot函数对数据集进行转换,以main_customer_code1,product_code1作为行索引,data_date1作为列索引,today_amount1作为数据值,最后对结果进行重置索引以便进一步分析。
摘要由CSDN通过智能技术生成