首页 > 解决方案 > 绘制分组数据,按熊猫中的多列分组

问题描述

我有一个根据两列分组的数据框。现在我想在 seaborn 中绘制 Date vs Confirmed 的数据。有没有什么好的方法可以做到。

grouped_series = cases.groupby(['Country/Region','ObservationDate'])['Confirmed','Deaths','Recovered'].sum()
print(grouped_series)

标签: pandasseaborndata-science

解决方案


您只能更改按日期时间分组的聚合:

cases.groupby(['ObservationDate'])['Confirmed'].sum().plot()

或者,如果需要每个ObservationDate和的总和值Country/Region

cases.groupby(['Country/Region','ObservationDate'])['Confirmed'].sum().unstack(0).plot()

推荐阅读