threshold = 10
for col in df.columns:
    value_counts = df[col].value_counts()
to_remove = value_counts[value_counts <= threshold].index
df[col].replace(to_remove, np.nan, inplace=True)
Remove low frequency values from pandas.dataframe