Skip to content
Advertisement

Grouping by multiple columns to find duplicate rows pandas

I have a df

JavaScript

I want to group by val1 and val2 and get similar dataframe only with rows which has multiple occurance of same val1 and val2 combination.

Final df:

JavaScript

Advertisement

Answer

You need duplicated with parameter subset for specify columns for check with keep=False for all duplicates for mask and filter by boolean indexing:

JavaScript

Detail:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement