pandas - 绘制分组数据,按熊猫中的多列分组
问题描述
我有一个根据两列分组的数据框。现在我想在 seaborn 中绘制 Date vs Confirmed 的数据。有没有什么好的方法可以做到。
grouped_series = cases.groupby(['Country/Region','ObservationDate'])['Confirmed','Deaths','Recovered'].sum()
print(grouped_series)
解决方案
您只能更改按日期时间分组的聚合:
cases.groupby(['ObservationDate'])['Confirmed'].sum().plot()
或者,如果需要每个ObservationDate
和的总和值Country/Region
:
cases.groupby(['Country/Region','ObservationDate'])['Confirmed'].sum().unstack(0).plot()
推荐阅读
- drake - 输入端口的索引是什么意思?
- kubernetes - 在 k8s 集群上运行的 ansible 的正确 dockerfile
- c# - 搜索字典值的字符串,然后用字典的键替换匹配的值?
- c++ - 计算树中大于输入名称的名称数量的函数
- authentication - 我正在尝试通过在应用程序之间共享 cookie(登录和网页)在 .net core 3.1 中实现 SSO
- shell - 使用shell脚本从hive查询结果中查找字符串并提取值?
- apache-spark - 从 Kafka 读取数据时如何优化 Spark Streaming 作业的延迟?
- c# - 如何从页面模型中的字节数组从 .net core razor 页面渲染 PDF
- reactjs - 发送数据 React 到 Node
- r - R:通过向量对矩阵进行索引,每行或列都有单独的索引