the pandas dataframe replaces values on multiple column conditions

If your original DF is

  ProductDescription ProductType
0                Art   Accessory
1             Mirror   Accessory
2        Western Art   Accessory
3             Tassel   Accessory
4           Hardware   Accessory
5             Mirror   Accessory

You can do the following:

mirror_filter = (df['ProductType'] == 'Accessory') & (df['ProductDescription'] == 'Mirror')
df.loc[mirror_filter, 'ProductType'] = df['ProductDescription']

And your resulting DF should be:

  ProductDescription ProductType
0                Art   Accessory
1             Mirror      Mirror
2        Western Art   Accessory
3             Tassel   Accessory
4           Hardware   Accessory
5             Mirror      Mirror

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top