I have a large data set in the following format:
import pandas as pd
df1 = pd.DataFrame({'Date':['01/02/2020' , '01/03/2020', '01/04/2020','01/02/2020' , '01/03/2020', '01/04/2020','01/02/2020' , '01/03/2020', '01/04/2020'],
'From': ['RU', 'RU', 'RU','USA', 'USA', 'USA','ME', 'ME', 'ME'],
'To': ['JK', 'JK', 'JK','JK', 'JK', 'JK','JK', 'JK', 'JK'],
'Distance':[ 40000, 40000, 40000,30000, 30000, 30000,20000, 20000, 20000],
'Days': [8,8,8,6,6,6,4,4,4]})
df2 = pd.DataFrame({'Date':['01/02/2020' , '01/03/2020', '01/04/2020','01/02/2020' , '01/03/2020', '01/04/2020','01/02/2020' , '01/03/2020', '01/04/2020'],
'Contract': ['OrangeTier', 'OrangeTier', 'OrangeTier','AppleTier', 'AppleTier', 'AppleTier','GrapeTier', 'GrapeTier', 'GrapeTier'],
'Price':[ 10000, 15000, 20000,30000, 35000, 1000,45000, 20000, 21000]})
I would like to add a column to df1, which looks up the Contract 'OrangieTier', matches the dates in df1 with df2 and returns the price. Resulting in the dataframe looking something like this:
df1 = pd.DataFrame({'Date':['01/02/2020' , '01/03/2020', '01/04/2020','01/02/2020' , '01/03/2020', '01/04/2020','01/02/2020' , '01/03/2020', '01/04/2020'],
'From': ['RU', 'RU', 'RU','USA', 'USA', 'USA','ME', 'ME', 'ME'],
'To': ['JK', 'JK', 'JK','JK', 'JK', 'JK','JK', 'JK', 'JK'],
'Distance':[ 40000, 40000, 40000,30000, 30000, 30000,20000, 20000, 20000],
'OrangeTier':[10000, 15000, 20000,10000, 15000, 20000,10000, 15000, 20000],
'Days': [8,8,8,6,6,6,4,4,4]})
I then want to multiply OrangeTier by Days and overwrite the OrangTier column with the result.