I have a dataframe with all available options for sale:
options = pd.DataFrame({'Name':['a', 'b', 'c', 'd'],
'Price':[1,3,6,4],
'Size':[12,32,44,68],
'Content':[10,8,22,20]}
And a list of needs:
criteria = pd.DataFrame({'Customer':['a1', 'b2', 'c3', 'd4'],
'MinSize':[8,20,12,40],
'MinContent':[18,6,21,4]}
I need to get the lowest price from the options that meets the minimum criteria, resulting in:
pd.DataFrame({'Customer':['a1', 'b2', 'c3', 'd4'],
'MinSize':[8,20,12,40],
'MinContent':[18,6,21,4],
'MatchingOption':['d','b','c','d']}
This would be the equivalent of a TOP 1 WHERE Content >= MinContent AND Size >= MinSize ORDER BY Price ASC in SQL.
How do I join dataframes based on the TOP 1 result of an ordered list of matching records?