From the dataframe which row contains one specific product,
data = [['Alpha', '#10','Apple','2020-10-01',4],
['Alpha', '#10','Tomatoes','2020-10-15',1.5],
['Beta', '#12','Banana', '2019-03-06', 2],
['Beta', '#14','Dragonfruit', '2020-04-05', 3],
['Charlie', '#16','Watermelon', '2019-01-02', 5]]
df = pd.DataFrame(data, columns = ['customer_name', 'order_number','product_variant','date','net_sales'])
I want to merge the rows so that one row contains one order number. Expected df
data_expected = [['Alpha', '#10',np.NaN,'Apple','Tomatoes','2020-10-01','2020-10-15',5.5],
['Beta', '#12','#14','Banana','Dragonfruit','2019-03-06','2020-04-05',5],
['Charlie', '#16',np.NaN,'Watermelon',np.NaN,'2019-01-02',np.NaN,5]]
df_expected = pd.DataFrame(data_expected, columns = ['customer_name','order_number_1', 'order_number_2','product_variant_1','product_variant_2','date_1','date_2','net_sales'])
In the real dataframe, one customer may have more than 2 products within the same order number, and may have more than 2 order numbers, and more than 2 dates as well (as in the real world).