python-3.x - How to sum data and join columns using Pandas
问题描述
I want to sum values in data
from this:
to this:
but the problem is, the data doesn't add up but they like 11, 1111
here is my code:
df_data.insert(loc=2, column='Jumlah', value='1')
df_data.pivot_table(index='Kecamatan', columns='Status', aggfunc='sum', fill_value=0)
And how I can make the columns only KECAMATAN NEGATIF ODP ODPSELESAI OTG PDP
Thank you guys.
解决方案
请注意,插入列 ( Jumlah ) 的值是一个字符串。在下一条指令中,您将尝试生成一个对该列求和的数据透视 表。
但是,如果您尝试对文本值求和,它实际上意味着concatenation。
为了解决问题,将第一条指令更改为:
df_data.insert(loc=2, column='Jumlah', value=1)
即删除1周围的撇号。
然后此列将是int类型,并将根据您的需要进行汇总。
推荐阅读
- php - 使用 docker-compose 创建数据库时出现错误
- android - 如何创建像android toast这样的确认视图
- mysql - 操作不同的表并显示来自一个表的信息
- python - 维度未知时如何创建一维范围张量?
- python-3.x - 了解python中的迭代器和zip
- javascript - 查看如何使用 input type=color 更改颜色
- c# - 按日期过滤时缺少 EFCore 3.1 产品
- birt - BIRT - onCreate 脚本未运行
- c# - 如何在拥有属性的同时从游戏对象获取第一个脚本:Unity
- java - 使用正则表达式匹配可选字符串的 Java 字符串