Expand/ungroup dataframe
Solution 1:
My opinion your solution is good, alternative with range
instead list is better:
df3 = df.merge(pd.DataFrame({'month':range(1, 13)}), how='cross')
df3['goal'] = (df3['goal']/12).astype(int)
Another idea without cross join with Index.repeat
for new rows and DataFrame.assign
with numpy.tile
for repeat months:
df = (df.loc[df.index.repeat(12)]
.reset_index(drop=True)
.assign(goal = lambda x: x['goal']/12,
month = np.tile(range(1, 13), len(df.index))))