I have used the following code to display top 3 products of each retailer
baseline_df = baseline_df.groupby(['RtrName'])['Product'].agg(lambda x:x.value_counts().index[0:3]).to_frame().reset_index()
The result of this is a dataframe with two columns - RtrName and Product but each row in the Product column has 3 values split by a comma (,)
Result Output:
RtrName Product
RtrName_a Product1,Product2,Product3
RtrName_b Product1,Product2,Product3
I want to have my dataframe in a way like : Expected Output
RtrName_a Product1
Product2
Product3
RtrName_b Product1
Product2
Product3
How do I achieve this?