#!/usr/bin/env python3
import pandas as pd
import numpy as np

times = pd.date_range('1/1/2011', periods=72, freq='M')
times = times[(times < times[20]) | (times > times[40])]

df = pd.DataFrame({"value" : np.random.rand(len(times)), "times" : times, "group": np.random.randint(4, size=len(times))})
df = df.set_index("times")

groupped = df.groupby("group")
g = groupped.apply(lambda group: (group.index.to_series().diff() > np.timedelta64(60, "D")).astype(int).cumsum())
# How to get back the values of g into the df dataframe? So that each row has the corresponding computed data into a new column?