Reputation: 61
I have a data frame which looks like this:
Plant Date Item unitsSold
1 10-oct A 15
1 11-Oct A 20
1 12-Oct A 10
2 10-Oct B 19
2 11-Oct A 20
2 12-Oct C 10
And another data set which look like this:
Plant Date Item unit Price
1 10-Oct A,B 10 ---That means both A and B have same unit price
1 11-Oct A 14
1 12-Oct A,B,C 10 ----That means both A, B and C have same price
2 10-oct A,B,C 15
2 11-Oct A 10
3 12-Oct A,C 20
Now i want my output to look like this:
Plant Date Item unit Price A.UnitsSold B.Unitssold C.unitssold
1 10-Oct A,B 10 15 0 0 --Since only a was sold on 10-oct
1 11-Oct A 14 20 0 0
1 12-Oct A,B,C 10 10 0 0
2 10-oct A,B,C 15 0 19 0
2 11-Oct A 10 20 0 0
3 12-Oct A,C 20 0 0 10
Can anyone please tell me how to get the columns for unit sold. Note- there can be any number of style
Upvotes: 1
Views: 77
Reputation: 899
df1.merge(df2, left_on='lkey', right_on='rkey')
YOU CAN get an idea from this merge code or this question:
might helps : stackoverflow.com/questions/37113173/…
Upvotes: 0