def differ(df):
    delta = df.sample_date.diff().abs()
cond = delta.notnull() & (delta < np.timedelta64(8, 'W'))
return df[cond].max()
delta = df.groupby(['dob', 'name']).apply(differ)
Apply function to a MultiIndex dataframe with pandas/python