
数据透视表是 Excel 最常用的分析工具。pandas 的 pivot_table 一行代码生成。一、读取与透视importpandasaspd dfpd.read_excel(销售数据.xlsx)pivotpd.pivot_table(df,values销售额,index城市,columns品类,aggfuncsum,fill_value0,marginsTrue,margins_name合计)二、多级透视pivotpd.pivot_table(df,values销售额,index[城市,销售员],columns季度,aggfunc[sum,mean])三、多个统计值pivotpd.pivot_table(df,values销售额,index城市,aggfunc{销售额:[sum,mean,count,max]}) 觉得有用的话点赞 关注【张老师技术栈】吧