如何总结垃圾箱的Y值而不是平均值?

时间:2017-08-04 11:08:17

标签: python pandas matplotlib seaborn

我有以下数据框data

import pandas as pd
from io import StringIO
data = pd.read_table(StringIO("""time_diff  avg_trips_per_day
631         1.0
231         1.0
431         1.0
7031        1.0
17231       1.0
20000       20.0
21000       15.0
22000       10.0"""), delim_whitespace=True)

我创建了一个条形图,如下:

import seaborn as sns
data['timegroup'] = pd.qcut(data['time_diff'], 3)
sns.barplot(x='timegroup', y='avg_trips_per_day', data=data)

目前,每个bin(avg_trips_per_day)的值为timegroup,并计算平均值avg_trips_per_day。 但是,我想要为每个bin avg_trips_per_day总结timegroup的值,而不是使用mean。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:3)

使用barplot的估算参数:

sns.barplot(x='timegroup', y='avg_trips_per_day', data=data, estimator=sum)

enter image description here