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!
Copyright Notice:Content Author:「jeangelj」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/49636459/python-panda-overwrite-value-based-on-conditional-in-other-column