new = df.groupby(pd.TimeGrouper('5Min'), as_index=False).apply(lambda x: x[
    'val'])
df['period'] = new.index.get_level_values(0)
how to create a group ID based on 5 minutes interval in pandas timeseries?