mardi 3 avril 2018

Python panda overwrite value based on conditional in other column

Working with the dataframe df in python pandas:

Product_ID  | Category  | Sub_Cat
32432           0         Gadget
24085         Big Tech    Computer
54398         Small Tech  Gadget
97456           0         Computer

I am working on a new column, where I will over-write the Sub_Cat value with the Category value, if it is not 0.

This is the output I am looking for:

Product_ID  | Category  | Sub_Cat         | Cat_for_Analysis
32432           0         Gadget            Gadget
24085         Big Tech    Computer          Big Tech
54398         Small Tech  Gadget            Small Tech
97456           0         Computer          Computer

Thank You!

Aucun commentaire:

Enregistrer un commentaire