多彩编程 多彩编程MZPH · CODE BLOG
ARTICLE DETAIL

文章详情

深耕前端与后端开发技术的一线实战笔记与踩坑复盘。

Python 批量处理 Excel 数据透视表——pandas 实战

Python 批量处理 Excel 数据透视表——pandas 实战 数据透视表是 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]}) 觉得有用的话点赞 关注【张老师技术栈】吧
返回列表