[英]Python, pandas: summing a column based on multiple other columns and putting it into a new dataframe
[英]merge a dataframe based on one column and summing the other columns - Python
我正在尋找基於一列合並其他列的 dataframe 。 我試圖通過 df.loc 組合 sum 來做到這一點,並且已經廣泛搜索了 Stack。 如果你們有任何建議,非常歡迎他們:)
原來的:
日期 | 值 x | 值 y |
---|---|---|
1920 年 13 月 3 日 | 1 | 0 |
1920 年 13 月 3 日 | 0 | 1 |
30-4-1920 | 0 | 1 |
30-4-1920 | 1 | 1 |
所需的 Output:
日期 | 值 x | 值 y |
---|---|---|
1920 年 13 月 3 日 | 1 | 1 |
30-4-1920 | 1 | 2 |
先感謝您!
“df”是 dataframe。 我認為日期列是字符串數據類型。
function 的小組完成了這項工作。
df.groupby(['date']).sum()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.