I have first pandas dataframe like following
trans_df
code price date time product
12023 71.23 01-01-2018 06:23:00 MS
12023 61 01-01-2018 07:56:00 HS
12023 71.23 01-01-2018 08:34:00 MS
12023 71.30 01-01-2018 06:03:00 MS
12023 61 01-01-2018 11:43:00 HS
12023 71.23 01-01-2018 10:11:00 MS
12023 71.23 01-01-2018 04:23:00 MS
12023 72.23 02-01-2018 10:11:00 MS
12023 72.23 02-01-2018 04:23:00 MS
Now, I have master price dataframe from where I am checking whether the price set in trans_df
is correct or not basis the transaction date and time is between effective_date_from
and effective_date_to
in master_price
for that particular product
master_price
code price effective_date_from effective_date_to time_from time_to product
12023 71.23 01-01-2018 02-01-2018 06:00:00 05:59:00 MS
12023 61 01-01-2018 02-01-2018 06:00:00 05:59:00 HS
12023 72.23 02-01-2018 03-01-2018 06:00:00 05:59:00 MS
Desired dataframe would be
trans_df
code price date time product flag actual_price
12023 71.23 01-01-2018 06:23:00 MS match 71.23
12023 61 01-01-2018 07:56:00 HS match 61
12023 71.23 01-01-2018 08:34:00 MS match 71.23
12023 71.30 01-01-2018 06:03:00 MS mismatch 71.23
12023 61 01-01-2018 11:43:00 HS match 61
12023 71.23 01-01-2018 10:11:00 MS match 71.23
12023 71.23 01-01-2018 04:23:00 MS nan nan
12023 72.23 02-01-2018 10:11:00 MS match 72.23
12023 72.23 02-01-2018 04:23:00 MS match 72.23