Q: Pandas Dataframe Merge on 2 Columns Including Conditional If Merge: If Date in df_2 is Between Two Other Dates in df_1 I have the following sample data frames: 
df_1:
from datetime import datetime
import pandas as pd

>>> df_1 = pd.DataFrame( 
 {"SVDiscrep_Merge": ["2081916SAN", "2081242DFW", "2081248ORD","20874CLE", "2081740DEN"],
 "RON_DATE": [datetime(2017,6,1), datetime(2017,6,4), datetime(2017,6,6), datetime(2017,6,7), datetime(2017,6,8)],
 "Next SV1 Date": [datetime(2017,6,4), datetime(2017,6,6), datetime(2017,6,7), datetime(2017,6,8), datetime(2017, 6, 18)]})

>>> df_1

SVDiscrep_Merge     RON_DATE    Next SV1 Date
2081916SAN          6/1/2017    6/4/2017    
2081242DFW          6/4/2017    6/6/2017
2081248ORD          6/6/2017    6/7/2017
20874CLE            6/7/2017    6/8/2017
2081740DEN          6/8/2017    6/18/2017

df_2:
>>> df_2 = pd.DataFrame( 
 {"SVDiscrep_Merge": ["2081916SAN", "2081916SAN", "2081916SAN","2081740DEN"],
 "REPORT_DT": [datetime(2017,6,1), datetime(2017,6,3), datetime(2017,6,4), datetime(2017,6,9)],
 "ColA": ["A", "B", "C", "D"]})

>>> df_2

SVDiscrep_Merge REPORT_DT   ColA
2081916SAN      6/1/2017    A
2081916SAN      6/3/2017    B
2081916SAN      6/4/2017    C
2081740DEN      6/9/2017    D

I want to employ the following logic: 


*

*Left merge df_2 into df_1 if (and only if) SVDiscrep_Merge is equal in both dataframes and 

*REPORT_DT column is >= date in RON_DATE and < date in Next SV1 Date in df_1.     
This is my desired output: 
SVDiscrep_Merge     RON_DATE    Next SV1 Date  ColA 
2081916SAN          6/1/2017    6/4/2017       A    
2081916SAN          6/4/2017    6/6/2017       B
2081916SAN          6/6/2017    6/7/2017
2081242DFW          6/4/2017    6/6/2017    
2081248ORD          6/6/2017    6/7/2017
20874CLE            6/7/2017    6/8/2017
2081740DEN          6/8/2017    6/18/2017      D

I know how to do the merge in python code if I did not have that date logic... but with that date logic (after searching Google) I am at a loss. 

A: You could left merge on SVDiscrep_Merge, then filter the result using the following boolean mask:
mask = (((result['RON_DATE'] <= result['REPORT_DT']) 
         & (result['REPORT_DT'] < result['Next SV1 Date'])) 
        | pd.isnull(result['REPORT_DT']))


import datetime as DT 
import pandas as pd

df_1 = pd.DataFrame( 
 {"SVDiscrep_Merge": ["2081916SAN", "2081242DFW", "2081248ORD","20874CLE", "2081740DEN"],
 "RON_DATE": [DT.datetime(2017,6,1), DT.datetime(2017,6,4), DT.datetime(2017,6,6), DT.datetime(2017,6,7), DT.datetime(2017,6,8)],
 "Next SV1 Date": [DT.datetime(2017,6,4), DT.datetime(2017,6,6), DT.datetime(2017,6,7), DT.datetime(2017,6,8), DT.datetime(2017, 6, 18)]})

df_2 = pd.DataFrame( 
 {"SVDiscrep_Merge": ["2081916SAN", "2081916SAN", "2081916SAN","2081740DEN"],
 "REPORT_DT": [DT.datetime(2017,6,1), DT.datetime(2017,6,3), DT.datetime(2017,6,4), DT.datetime(2017,6,9)],
 "ColA": ["A", "B", "C", "D"]})

result = pd.merge(df_1, df_2, on='SVDiscrep_Merge',  how='left')
mask = (((result['RON_DATE'] <= result['REPORT_DT']) 
         & (result['REPORT_DT'] < result['Next SV1 Date'])) 
        | pd.isnull(result['REPORT_DT']))
result = result.loc[mask].drop('REPORT_DT', axis=1)
print(result)

yields
  Next SV1 Date   RON_DATE SVDiscrep_Merge ColA
0    2017-06-04 2017-06-01      2081916SAN    A
1    2017-06-04 2017-06-01      2081916SAN    B
3    2017-06-06 2017-06-04      2081242DFW  NaN
4    2017-06-07 2017-06-06      2081248ORD  NaN
5    2017-06-08 2017-06-07        20874CLE  NaN
6    2017-06-18 2017-06-08      2081740DEN    D

This is not quite the desired result you posted, but it is consistent with the description of the logic. 
