【发布时间】:2020-04-13 20:03:55
【问题描述】:
我的数据框有 3 列:年份。主因,死亡。我想找出每年的主要死因死亡总数。我做了以下事情:
totalDeaths_Cause = df.groupby(["Year", "Leading Cause"])["Deaths"].sum()
这导致:
The total number of deaths for :
Year Leading Cause
2009 Hypertension 26
2010 All Other Causes 2140
2011 Cerebrovascular Disease 281
Immunodeficiency 70
Parkinson Disease 180
2012 Cerebrovascular Disease 102
Disease1 183
Diseases of Heart 76
2013 Cerebrovascular Disease 386
Parkinson Disease 372
Self-Harm 17
Name: Deaths, dtype: int64
现在我想获得每年最大的 2 个值(用于死亡)和主要的原因:
The total number of deaths for :
Year Leading Cause
2009 Hypertension 26
2010 All Other Causes 2140
2011 Cerebrovascular Disease 281
Parkinson Disease 180
2012 Disease1 183
Cerebrovasular disease 102
2013 Cerebrovascular Disease 386
Parkinson Disease 372
提前感谢您的帮助!
【问题讨论】:
标签: python pandas pandas-groupby