My data is a list of products in a dataframe with other sales and ordering information.
product_cat_dict = {"T-Shirt": "T-Shirt",
"Top": "T-Shirt",
"Vest": "T-Shirt",
"Sweater": "Sweater"}
products = pd.DataFrame({"Product Name": ["T-Shirt White", "T-Shirt Black", "Top Orange", "Navy Vest", "Red Top", "Sweater Black"],
"Sales": [100, 200, 250, 50, 150, 300]})
I'm trying to add a new column onto the dataframe which contains just the product category from the product name column but I'd also like some of the products to be grouped together into the same category (as per the dictionary code).
My desired result is the following table:
I tried using a dictionary so it's easy to update in case any new products with undefined categories are added to the data. From reading other SO posts it looks like I need to use contains to do partial substring matching but I can't seem to return the actual matched value (rather than the original data). The best I could get was to return a list of Boolean responses with the below code.
products["Product Name"].str.contains("|".join(product_cat_dict.keys()))
Any help on how I can get to my desired result would be much appreciated.

