user10508414
user10508414

Reputation:

How to group by and count

Dataframe is below

user_id
1236
5842
1236

My out

user_id  count
1236    2
5842    1

result = df.groupby(['user_id']).count() not working

Upvotes: 1

Views: 40

Answers (1)

Kenan
Kenan

Reputation: 14124

Explicit

df.groupby(['user_id']).agg({'user_id': 'count'})

         user_id
user_id         
1236           2
5842           1

Upvotes: 2

Related Questions