您可以按箱和用户名进行分组,计算组大小,然后使用unstack():
unstack()
>>> groups = df.groupby(['username', pd.cut(df.views, bins)]) >>> groups.size().unstack() views (1, 10] (10, 25] (25, 50] (50, 100] username jane 1 1 1 1 john 1 1 1 1