I want to repeat a specific row of pandas data frame for a given number of times.
For example, this is my data frame
df= pd.DataFrame({
'id' : ['1','1', '2', '2','2','3'],
'val' : ['2015_11','2016_2','2011_9','2011_11','2012_2','2018_2'],
'data':['a','a','b','b','b','c']
})
print(df)
Here, "Val" column contains date in string format. It has a specific pattern 'Year_month'. For the same "id", I want the rows repeated the number of times that is equivalent to the difference between the given "val" column values. All other columns except the val column should have the duplicated value of previous row.
The output should be:

