首页 > 解决方案 > 通过 value_counts() 创建箱线图 [发生的事件数]

问题描述

我有以下数据框。每个条目都是一个发生的事件 [550624 个事件]。假设我们对每月每天发生的事件数量的箱线图感兴趣。

print(df)         
          Month  Day
0           4    1
1           4    1
2           4    1
3           4    1
4           4    1
      ...  ...
550619     10   31
550620     10   31
550621     10   31
550622     10   31
550623     10   31

[550624 rows x 2 columns]

df2 = df.groupby('Month')['Day'].value_counts().sort_index()
Month  Day
4      1      2162
       2      1564
       3      1973
       4      1620
       5      1860

10     27     2022
       28     1606
       29     1316
       30     1674
       31     1726
sns.boxplot(x = df2.index.get_level_values('Month'), y = df2)

sns.boxplot 的输出

我的问题是这种方式是否是创建这种视觉信息的最有效/直接的方式,或者我是否正在采取一种迂回的方式来实现这一点。有没有更直接的方法来实现这种视觉效果?

标签: pythonpandas

解决方案


推荐阅读