m = m.groupby(['U', 'Datetime'], as_index=False).size().reset_index()
m['a0'] = pd.to_datetime(m['Datetime']).dt.to_period('M')
m = m.drop(['Datetime', 0], axis=1)
m['a1'] = m.groupby('U')['a0'].shift(-1)
m['a2'] = m.groupby('U')['a0'].shift(-2)
print(m)
pandas - groupby and filtering for consecutive values