I have 2 dataframes:
df1
Time Apples Pears Grapes Peachs
10:00 3 5 5 2
11:00 1 0 2 9
12:00 20 2 7 3
df2
Class Item Factor
A Apples 3
A Peaches 2
A Pears 5
B NaN 4
I want to create a new column in df2 called Total
which item at 10:00 in df1, multiplied by the Factor for that item - this should only be done if they are in Class A.
This is how the final df should look
df2
Class Item Factor Total
A Apples 3 9
A Peaches 2 4
A Pears 5 25
B NaN 4
This is what I tried:
df2['Total'] = df1.setIndex().cols.isin((df2.Item) and (df2.Class==A)) * df2.Factor