My example is made up. I'd like to figure it out with apply() and lambda, though I've tried iterrows() too with no luck. I am trying to add a column to df2, that looks up values in df1, based on the 'item' combinations in each df2 row. Thanks in advance for your help.
import pandas as pd
import numpy as np
import random
names= ['A', 'B', 'C', 'D', 'E']
df1 = pd.DataFrame( np.arange(25).reshape(5,5), columns = names, index = names)
n=5
data = {'Item 1' : random.sample(names, n),
'Item 2' : random.sample(names, n)}
df2 = pd.DataFrame(data)
#I can't get this to work.
df2['New'] = df2.apply(lambda x: df1.loc[df2.loc[x, 'Item 1'], df2.loc[x, 'Item 2']], axis=1)
#Since this works, I assume my error with apply and lambda. Thanks.
x=2
df1.loc[df2.loc[x, 'Item 1'], df2.loc[x, 'Item 2']]