简体   繁体   English

如何使用“groupby”的结果绘制 Seaborn FacetGrid?

[英]How do I plot a Seaborn FacetGrid with the result of the `groupby`?

I have the following pandas Dataframe :我有以下pandas Dataframe

             A  B              C
0   2017-01-01  1   4.199197e+06
1   2017-01-01  2   8.708300e+06
2   2017-01-01  3   5.401463e+06

the result of a groupby operation: groupby 操作的结果:

tot_reg = (sales.groupby(['A', 'B'])[['C']]
           .sum()
           .reset_index())

I would like an Seaborn sns.Facetgrid plotting A on the x-axis, C on the y-axis, for every B there is, I have:我想要一个Seaborn sns.Facetgrid在 x 轴上绘制A ,在 y 轴上绘制C ,对于每个 B,我有:

sns.FacetGrid(tot_reg, col='B', col_wrap=4)

but although it does count the unique B and draws the correct number of subplots, the plots are empty.但是尽管它确实计算了唯一的B并绘制了正确数量的子图,但这些图是空的。

How do I plot a Seaborn FacetGrid with the result of the groupby ?如何使用groupby的结果绘制 Seaborn FacetGrid ?

You need to map the plot command to facetgrid:您需要将 plot 命令映射到 facetgrid:

fg = sns.FacetGrid(df, col='B', col_wrap=4)
fg.map(sns.scatterplot, 'A','C')

Output:输出:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM