My input dataframe sample is like this:
Comment Type
1 I love this product Generic
2 Refund order amount for my returned item Refund
3 Price is high Merchandise
4 Product info doesn't match deal Deal
5 I love this product Merchandise
6 Rude service CustomerService
7 iPhone not available Merchandise
8 iPhone not available Inventory
9 Product info doesn't match deal Price
A comment can fall into multiple types. I am trying to group by comment and transform type as below using Python: [Expected Output]
Comment Generic Refund Price Deal Merchandise CustomerService Inventory
I love this product 1 0 0 0 1 0 0
Refund order amount for
my returned item 0 1 0 0 0 0 0
Price is high 0 0 1 0 0 0 0
Product info doesn't match deal 0 0 1 1 0 0 0
Rude service 0 0 0 0 0 1 0
iPhone not available 0 0 0 0 1 0 1
I tried below for grouping but I am unable to get it correct nor progress with expected output transformation:
df_group = inputDataframe.groupby(['comment'],as_index=False)
for key, item in df_group:
print(key)
print(item)
Please assist. Thanks!