Pandas实现DataFrame按行求百分数(比例数)
作者:肥宅_Sean 时间:2022-10-23 10:49:01
简述
Motivation
一般来说,每个部分的内容数量是较为容易获取的,但比例(百分数)这样的数据是二次数据,这样的操作很常见
比例的信息相比于纯粹的数字更体现的整体体系的内部变化迁移的过程
Contribution
给了实例,follow下就没问题了~
Codes
导入包的部分,我就不写了哈
这里假设每行是属于不同月份的数据
>>> df
a b c d e
month0 0 1 2 3 4
month1 5 6 7 8 9
month2 10 11 12 13 14
month3 15 16 17 18 19
变百分数
按列(即投影到列)求和
按行(即投影到行)除法
>>> df.div(df.sum(axis=1), axis=0)
a b c d e
month0 0.000000 0.100000 0.2 0.300000 0.400000
month1 0.142857 0.171429 0.2 0.228571 0.257143
month2 0.166667 0.183333 0.2 0.216667 0.233333
month3 0.176471 0.188235 0.2 0.211765 0.223529
来源:https://blog.csdn.net/a19990412/article/details/90745056
标签:Pandas,DataFrame,百分数,比例数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SQL Server 服务器优化技巧浅谈
2024-01-13 17:31:01
Python实现智能贪吃蛇游戏的示例代码
2023-01-28 13:39:36
![](https://img.aspxhome.com/file/2023/1/100861_0s.jpg)
pyqt5 从本地选择图片 并显示在label上的实例
2022-12-12 17:48:04
![](https://img.aspxhome.com/file/2023/1/94001_0s.jpg)
XML编程实例:用ASP+XML打造留言本
2008-05-04 13:37:00
Python制作爬虫抓取美女图
2021-05-15 12:47:45
![](https://img.aspxhome.com/file/2023/9/120399_0s.jpg)
python实现发送邮件及附件功能
2023-12-30 23:27:04
![](https://img.aspxhome.com/file/2023/0/109580_0s.jpg)
vue自定义tap指令及tap事件的实现
2024-05-09 09:25:15
Django表单提交后实现获取相同name的不同value值
2023-08-11 01:59:31
![](https://img.aspxhome.com/file/2023/4/62294_0s.jpg)
Python实现检测文件的MD5值来查找重复文件案例
2021-08-14 01:28:02
Bootstrap警告框(Alert)插件使用方法
2024-04-27 15:23:05
![](https://img.aspxhome.com/file/2023/1/135501_0s.jpg)
详解oracle mysql 中的“不等于“ <> != ^= is not
2024-01-25 03:35:08
Python爬虫之正则表达式基本用法实例分析
2022-12-20 17:02:16
![](https://img.aspxhome.com/file/2023/1/75361_0s.png)
python自动化运维之Telnetlib的具体使用
2022-09-24 22:11:16
Python返回真假值(True or False)小技巧
2023-12-30 21:56:18
![](https://img.aspxhome.com/file/2023/7/101427_0s.png)
微信小程序实现电影App导航和轮播
2024-04-18 09:49:32
![](https://img.aspxhome.com/file/2023/4/136204_0s.jpg)
MySQL 函数索引的优化方案
2024-01-23 03:13:36
Python正则表达式使用经典实例
2022-04-29 01:22:03
Java读取properties文件连接数据库的方法示例
2024-01-13 15:17:24
![](https://img.aspxhome.com/file/2023/5/96525_0s.jpg)
给网页添加打印功能按钮
2008-12-12 13:11:00
![](https://img.aspxhome.com/file/UploadPic/200812/12/print-68s.jpg)
python实现基于信息增益的决策树归纳
2022-05-20 14:22:47