相关疑难解决方法(0)

合并和总结 Pandas 中的几个值计数系列

我通常value_counts()用来获取某个值的出现次数。但是,我现在处理大型数据库表(无法将其完全加载到 RAM 中)并在不到 1 个月的时间内查询数据。

有没有办法存储结果value_counts()并将其与/添加到下一个结果中?

我想计算用户操作的数量。假设用户活动日志的结构如下:

# month 1
id    userId     actionType
1     1          a
2     1          c
3     2          a
4     3          a
5     3          b

# month 2
id    userId     actionType
6     1          b
7     1          b
8     2          a
9     3          c
Run Code Online (Sandbox Code Playgroud)

value_counts()在这些产品上使用:

# month 1
userId
1       2
2       1
3       2

# month 2
userId
1       2
2       1
3       1
Run Code Online (Sandbox Code Playgroud)

预期输出:

# month 1+2
userId
1       4
2 …
Run Code Online (Sandbox Code Playgroud)

python count pandas

3
推荐指数
1
解决办法
5974
查看次数

标签 统计

count ×1

pandas ×1

python ×1