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)
m = m.loc[(m['a0'] + 1 == m['a1']) & (m['a1'] + 1 == m['a2'])]
print(m)
m = pd.melt(m, id_vars=['U'], value_name='period')
m = m.drop(['variable'], axis=1)
m = m.sort_values('period').reset_index(drop=True)
print(m)
pandas - groupby and filtering for consecutive values