+ 2

How to print the count of each duplicate rows in pandas and filter it ?

0 Name age state point 1 Alice 24 NY 64 2 BOB 23 CA 46 3 BOB 23 CA 46 4 DAVE 34 TX 70 5 DAVE 34 TX 70 6 DAVE 34 TX 70 Print(df.groupby(["name","age","state"]).size() It will print the data like Name age state point Alice 24 NY 64 1 BOB 23 CA 46 2 DAVE 34 TX 70 3 However I want filter it by number of occurrence which is greater than 2 that is If count >=2 then Print this BOB 23 CA 46 2 DAVE 34 TX 70 3

12th Sep 2021, 12:28 PM
Vijay(v-star🌟)
Vijay(v-star🌟) - avatar
1 Respuesta
+ 1
Does the following code helps ? df2=df.groupby(["Name","age","state"])["point"].size().reset_index().rename(columns = {"point":"size"}) for i in range(len(df2.index)-1): if df2.loc[i,"size"] < 2: df2.drop(i,inplace=True) print(df2)
12th Sep 2021, 4:44 PM
Abhay
Abhay - avatar