I have a dataframe with sporadic dates as the index, and columns = \'id\' and \'num\'. I would like to pd.groupby the \'id\' column, and apply the reindex to e
pd.groupby
There's probably a slicker way to do this but this works:
def reindex_by_date(df): dates = pd.date_range(df.index.min(), df.index.max()) return df.reindex(dates).ffill() df.groupby('id').apply(reindex_by_date).reset_index(0, drop=True)