n = 8
dates = pd.date_range('1/1/2013', freq='D', periods=n)
df = DataFrame({'key': np.arange(n), 'date': dates, 'value': np.arange(n) * 10}
    )
df2 = DataFrame({'key': np.arange(n), 'valid_from': dates[[1, 1, 1, 1, 5, 5,
    5, 5]], 'valid_to': dates[[4, 4, 4, 4, 6, 6, 6, 6]], 'value': np.arange
    (n) * 100})
SQL like joins in pandas