I would like to simplify the number of categories for one variable. The piece of code below is working:
df.loc[(df['category'] == 'cat1')|(df['category'] == 'cat2')|(df['category'] == 'cat3')|...|(df['category'] == 'catn'),'category'] == 'other'
but I was wondering if I could do something like:
category_to_change = ['cat1','cat2','cat3',...,'catn']
for name in category_to_change:
df.loc[(df['category'] == name),'category'] == 'other'
(this doesn't work)
Any ideas how to do?