python - Python Pandas 聚合数据
问题描述
import pandas as pd
df=pd.read_csv('txn.csv')
print(df)
#printing the data
Date debit credit
0 01-12-2019 100.00 0.00
1 05-12-2019 200.00 500.00
2 01-12-2019 105.00 200.00
3 05-12-2019 10.00 100.00
我想打印汇总数据,即借方总和,贷方如下所述。
Date debit credit
01-12-2019 205.00 200.00
05-12-2019 210.00 600.00
有什么建议吗
解决方案
df.groupby('Date').sum()
请参阅文档https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.groupby.html
推荐阅读
- xml - XSD:独特的元素
- java - 使用 BouncyCastle 接受过期的 CRL
- .net - 缓存从 ASP.NET 核心 Web api 中的大量文件中读取的内容
- bash - 阅读默认网关的路由表?
- sql - 如何在 SQL Server 中将 YYYY-MM-DD HH:MM:SS 转换为 MM-DD-YYYY HH:MM:SS?
- android - Espresso 无法启动其他活动
- c++ - 从线程执行成员方法时出现分段错误
- angular - 检测 @ViewChild() 中的值何时发生变化
- javascript - 在 Vue 的组件脚本中使用 slot-scoped 数据
- automated-tests - VSTS 发布管道运行后如何测试?