Basically, I want to filter a Pandas DataFrame by the value_counts(), however, I also want to make an exception. For example, this is a sample code:
import pandas as pd
df = pd.DataFrame({
'city': ['NYC', 'NYC', 'SYD', 'NYC', 'SEL', 'NYC', 'NYC']
})
value_counts = df['city'].value_counts()
to_remove = value_counts[value_counts <= 3].index
df = df[(~df.city.isin(to_remove)) & (df.city == 'SEL')]
I would like to display both the NYC, which meets the value_counts() condition, but I also want to make an exception for 'SEL'