I have a table in pandas:
import pandas as pd df = pd.DataFrame({ \'LeafID\':[1,1,2,1,3,3,1,6,3,5,1], \'pidx\':[10,10,300,10,30,40,20,10,30,45,20],
This is a straightforward application of filter after doing a groupby. In the data you provided, a value of 20 for pidx only occurred twice so it was filtered out.
df.groupby('pidx').filter(lambda x: len(x) > 2) LeafID count pidx pidy 0 1 10 10 20 1 1 20 10 20 3 1 40 10 20 7 6 50 10 43