如何在 Python 中按每个月对每个用户 ID 的推文数量进行分组?

时间:2021-07-21 18:09:57

标签: python pandas dataframe

我的高音数据框如下所示:

    User_id         Year    Month
0   1.367900e+04    2020    10
1   1.367900e+04    2020    11
2   1.367900e+04    2020    11
3   1.367900e+04    2019    11
4   2.313400e+04    2019    12

每个 user_id 行代表用户的一条推文。 我需要添加一个名为“Tweets_count”的列,用于计算每个月用户的推文数量。

数据框应如下所示:

    User_id         Year    Month   Tweet_count
0   1.367900e+04    2020    10      5
1   1.367900e+04    2020    11      7
2   1.367900e+04    2020    9       10
3   1723647         2019    11      50
4   1723647         2019    12      20

0 个答案:

没有答案
相关问题