I need some help to do some complex lookups and enrichment. I need this working in Python 3.5
Here is the scenario. I have 2 dataframes: dfMaster and dfLookup
dfMaster has columns fromDate, toDate, fromLocation, toLocation, LookupKey (This dataframe will get additional rows every day) The data in dfMaster has 2 rows:
1-May-2018, 3-May-2018, Amsterdam, Rotterdam, NaN
2-May-2018, 5-May-2018, Rotterdam, Amsterdam, NaN
dfLookup has columns lookupDate, lookupFromLocation, lookupToLocation, someKey (This is a fairly static dataframe) The data in dfLookup has 2 rows:
3-May-2018, Rotterdam, Amsterdam, Key1
5-May-2018, Rotterdam, Amsterdam, Key1
I want to do the following matching on dfMaster:
- I want to pick dfLookup.lookupDate and check its between dfMaster.fromDate and dfMaster.toDate
- Next, I want to check the lookupFromLocation matches fromLocation
- Finally, I want to check the lookupToLocation matches toLocation
If all of this matches, I want to pick dfLookup.Key1 and put it into dfMaster.LookupKey
The final output should look like this: 1-May-2018, 3-May-2018, Amsterdam, Rotterdam, NaN
2-May-2018, 5-May-2018, Rotterdam, Amsterdam, Key1
Not finding an easy way to do this. I also want the final output to not be only filtered by what I enrich, but also by those rows that are not enriched
Thanks