我有以下数据框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。我怎样才能做到这一点?
答案 0 :(得分:3)