我有一个有两列的熊猫数据集:
(city)
我想向每个城市展示最频繁的5-6模式。
hlt_downsampled_eng.groupby('Poblacion')['patologie'].count().nlargest(6)我的想法是这样的输出:
Barcellona
Fever 5230
Rheum 2000
headache 300
cough 240
Tessara
diarrhea 5230
flu 1000
headache 300
cough 240我怎样才能用熊猫来实现它呢?
我知道我应该做的是:每城市组>每组病理>病理计数>聚合
发布于 2020-12-09 19:56:46
你可以试两次群:
# value_counts makes more sense to me
(hlt_downsampled_eng.groupby('Poblacion')['patologie'].value_counts()
.groupby('Poblacion').nlargest(6) # head(6) should also work
)https://stackoverflow.com/questions/65223878
复制相似问题