Imagine a below dataset. INPUT DATASET
id status type location bb_count vo_count tv_count
123 open r hongkong 1 0 4
456 open r hongkong 1 7 2
456 closed p India 0 6 1
OUTPUT DATASET I need to insert a row with product type if any(bb_count, tv_count, vo_count) is greater than 0.
id status type location product
123 open r hongkong bb
123 open r hongkong tv
456 open r hongkong bb
456 open r hongkong vo
456 open r hongkong tv
456 closed p India vo
456 closed p India rv
what I tried:
def insert_row(df):
if df["bb_count"] > 0:
print("inserting bb row")
if df["tv_count"] > 0:
print("inserting tv row")
if df["vo_count"] > 0:
print("inserting vo row")
df.apply(insert_row, axis=1)
But I'm not getting the exact output.