I want to filter product_type which is having "others" for all ticket_id and replace "others" with voice.
Sample dataframe
ticket_id network product_type
123 AAA tv
345 AAA others
567 BBB others
678 CCC others
789 DDD broad
Expected output
ticket_id network product_type
123 AAA tv
345 AAA voice
567 BBB voice
678 CCC voice
789 DDD broad
I tried the below function but it gives an error:
ERROR:root:The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
def product_mapping(df):
try:
data = df.query('product_type == "others"')['ticket_id']
if data:
data["product_type"] = data["product_type"].replace({"others": "voice"})
return data
else:
return df
except Exception as error:
logger.error(error)
df.query('product_type == "others"')?icket_idif theproduct_typeis other