I have a Pandas DataFrame of the form:
Current
product_typ
[Milo, Milk, Sugar]
[Water, Tea, Milo]
[Bread, Water]
[Bread, Water, Milo]
[Salt, Water, Milo]
[Milo, Milk, Water, Bread]
[Salt, Milk, Bread]
[Milo, Milk]
I would like to create a new column with regex of the form. Keep in mind that it is a Pandas DataFrame
Expected Output
product_typ matched_col
[Milo, Milk, Sugar] Product_Milo_Milk_Sugar
[Water, Tea, Milo] Product_Water_Tea_Milo
[Bread, Water] Product_Bread_Water
[Bread, Water, Milo] Product_Bread_Water_Milo
[Salt, Water, Milo] Product_Salt_Water_Milo
[Milo, Milk, Water, Bread] Product_Milo_Milk_Water_Bread
[Salt, Milk, Bread] Product_Salt_Milk_Bread
[Milo, Milk] Product_Milo_Milk
I tried to attempt this with str.findall matching the pattern works but the replacement got me quite thinking.