我有以下数据:
Date_reported Country_code Country WHO_region New_cases Cumulative_cases New_deaths Cumulative_deaths
0 2020-01-03 AF Afghanistan EMRO 0 0 0 0
1 2020-01-04 AF Afghanistan EMRO 0 0 0 0
2 2020-01-05 AF Afghanistan EMRO 0 0 0 0
3 2020-01-06 AF Afghanistan EMRO 0 0 0 0
4 2020-01-07 AF Afghanistan EMRO 0 0 0 0
... ... ... ... ... ... ... ... ...
243868 2022-10-23 ZW Zimbabwe AFRO 0 257893 0 5606
243869 2022-10-24 ZW Zimbabwe AFRO 0 257893 0 5606
243870 2022-10-25 ZW Zimbabwe AFRO 0 257893 0 5606
243871 2022-10-26 ZW Zimbabwe AFRO 0 257893 0 5606
243872 2022-10-27 ZW Zimbabwe AFRO 0 257893 0 5606
我想把所有的国家合并成一个表格,比如:
Date_reported New_cases Cumulative_cases New_deaths Cumulative_deaths
0 2020-01-03 0 0 0 0
1 2020-01-04 0 0 0 0
2 2020-01-05 0 0 0 0
3 2020-01-06 0 0 0 0
4 2020-01-07 0 0 0 0
... ... ... ... ... ... ... ... ...
243872 2022-10-27 sum of all country
我怎么能用熊猫来做呢?
您希望按日期列对数据进行分组,然后对每列求和:
df.groupby(['Date_reported'])['New_cases', 'Cumulative_cases', 'New_deaths', 'Cumulative_deaths'].sum()