user15729434
user15729434

Reputation:

How to count number of rows in terms of users id in pandas

I have a dataframe, it consists many users and their respective actions

What I need pandas to do is to count the number of rows in terms of user_iD

lets say if user_iD = 1 is repeated 30 or times it should remain in the dataframe otherwise pandas should remove all the user_iD enteries which are less than 30.

Upvotes: 0

Views: 970

Answers (1)

Xelvoz
Xelvoz

Reputation: 313

This could solve your problem.

userid_counts = A.user_iD.value_counts()
mask = userid_counts >= 30
filtered_userids = mask[mask].index

A = A[A.user_iD.isin(filtered_userids)]

Upvotes: 1

Related Questions