0

my tweeter data frame looks like this:

    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

each user_id row symbolize a tweet by the user. i need to add a column called "Tweets_count" that counts the number of tweets for user in each Month.

data frame should look like this:

    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
Cameron Riddell
  • 10,942
  • 9
  • 19
  • 2
    Does this answer your question? [Pandas, groupby and count](https://stackoverflow.com/questions/47320572/pandas-groupby-and-count) – Henry Ecker Jul 21 '21 at 18:12
  • 1
    From the duplicate -> `df.value_counts().reset_index(name='Tweet_count')` or `df.groupby(['User_id', 'Year', 'Month'])['User_id'].count().reset_index(name='Tweet_count')` – Henry Ecker Jul 21 '21 at 18:14
  • Hi, i need that each User_id will appear once for each Month and to count the number of appearances on that month under "tweet_count" column. how can i do it? @HenryEcker – Lidor Iluz Jul 22 '21 at 14:06

0 Answers0