小编Ana*_*d T的帖子

numpy中的groupby,计数和平均值,python中的pandas

我有一个看起来像这样的数据框:

       userId  movieId  rating
0           1       31     2.5
1           1     1029     3.0
2           1     3671     3.0
3           2       10     4.0
4           2       17     5.0
5           3       60     3.0
6           3      110     4.0
7           3      247     3.5
8           4       10     4.0
9           4      112     5.0
10          5        3     4.0
11          5       39     4.0
12          5      104     4.0
Run Code Online (Sandbox Code Playgroud)

我需要获取一个数据框,它具有唯一的 userId、用户的评分数和用户的平均评分,如下所示:

       userId    count    mean
0           1        3    2.83
1           2        2     4.5
2           3        3     3.5
3           4        2     4.5
4           5        3 …
Run Code Online (Sandbox Code Playgroud)

numpy python-3.x pandas jupyter

5
推荐指数
2
解决办法
9063
查看次数

标签 统计

jupyter ×1

numpy ×1

pandas ×1

python-3.x ×1