counts_col2 = df.groupby("Col2")["Col2"].transform(len) counts_col3 = df.groupby("Col3")["Col3"].transform(len) mask = (counts_col2 > 5) & (counts_col3 > 5) df[mask]