Is there a way that I can create a new column in a dataframe by selecting values from different columns from another dataframe based on some conditions in the first dataframe?
My data sets are like this:
df1 = pd.DataFrame(
    [['USA', 1992],
    ['China', 1993],
    ['Japan', 1994]],
    columns = ['Country', 'year'])
scores = pd.DataFrame(
    [['USA', 20, 30, 40],
    ['China', 5, 15, 30],
    ['Japan', 30, 50, 40],
    ['Korea', 10, 15, 20],
    ['France', 10, 12, 15]],
    columns = ['Country', 1992, 1993, 1994])
And my desired dataset would be:
df = pd.DataFrame(
    [['USA', 1992, 20]
    ['China', 1993, 15]
    ['Japan', 1994, 40]],
    columns = ['Country', 'year', 'score'])
I have tried using apply with a lambda function but it gives me a
KeyError: ('Country', u'occurred at index Country')
the line that I have tried is:
df1['score'] = df.apply(lambda x: scores[scores['Country'] == x['Country']][x['year']][1])
Thank you in advance!