Skip to content
Advertisement

How to select rows in Pandas dataframe where value appears more than once

Let’s say I have the Pandas dataframe with columns of different measurement attributes and corresponding measurement values.

JavaScript

How can I filter this dataframe to only have measurements that appear more than X number of times? For example, for this dataframe I want to get all rows with more than 5 measurements (lets say only parameters ‘A’ and ‘B’ appear more than 5 times) to get a dataframe like below.

JavaScript

Advertisement

Answer

You can use value_counts + isin

JavaScript

For example, where K = 2 (get all items which have more than 2 readings) –

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