Please assist in creating a python function. I have two dataframes, DF1 and DF2. I'd like to add a column to DF1, DF1['Score'], which is based on values contained in DF1 that match the values in DF2.
DF1:
DF2:
import pandas as pd
DF1 = pd.DataFrame({
'Age':[25, 54, 33],
'Income' :[10203, 23822, 84823],
'Contract Length':[18, 12, 36],
#'Score':[]
})
DF2 = pd.DataFrame({
'variable':['Age', 'Age', 'Age', 'Age',
'Income', 'Income', 'Income', 'Income',
'Contract Length', 'Contract Length', 'Contract Length', 'Contract Length'],
'LQ':[ 25, 32.25, 39.5, 46.75, 10203, 28858, 47513, 66168, 12, 18, 24, 30],
'UQ':[ 32.25, 39.5, 46.75, 54, 28858, 47513, 66168, 84823, 18, 24, 30, 36],
'Score':[5, 10, 15, 20, 10, 15, 20, 25, 15, 20, 25, 30]
})
Take customer UID 1 in DF1, since he is 25, with an income of 10,203 and contract length of 18; based on DF2 I want to be able to add a score of 30 to DF1['Score'] for customer 1, calculated as 5 (for age 25 to 32.5) + 10 (for income 10,2013 to 28,858) + 15 (for contract length of 12 to 18).
Please assist in creating a python function to add the correct scores to DF1['Score'] for all customers.

