I have 2 dataframes. I currently have the code below but I'm now sure how to search for the customer ID in dataframe 2 to place the quantity in the corresponding product column.
Dataframe 1 (INPUT DF):
CustomerID Product Quantity
123 Ball 2
123 Leash 2
456 Ball 1
Dataframe 2 (OUTPUT DF):
CustomerID Ball Leash
123 0 0
456 0 0
I want them to look like this
Dataframe 1 (INPUT):
CustomerID Product Quantity
123 Ball 2
123 Leash 2
456 Ball 1
Dataframe 2 (OUTPUT):
CustomerID Ball Leash
123 2 2
456 1 0
Please let me know if I need to explain further.
### Adding how many for each customer
for index, row in df2.iterrows():
ID = row["Customer_ID"]
Product = row["Product_Name"]
Quantity = row["Quantity"]
df.loc[df.index[df[ID]], Product] = Quantity