import pandas as np
import numpy as np
df = pd.DataFrame(np.random.randint(0, high=9, size=(100, 2)), columns=['A',
    'B'])
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)
Удалить низкочастотные значения из pandas.dataframe