Skip to content
Advertisement

Pandas Join Two Dataframes According to Range and Date

I have two dataframes like this:

JavaScript

I want to bring the RATE values to the second df in accordance with the DATE. Also, the AMOUNT and DAY values in the relevant DATE must be within the appropriate range (MAX_AMOUNT & MIN_AMOUNT, MAX_DAY & MIN_DAY).

Desired output like this:

JavaScript

Could you please help me about this?

Advertisement

Answer

Use merge first with filter columns by Series.between and then use Series.map for RATE column with first matched ID – added DataFrame.drop_duplicates:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement