I need to insert rows based on the column week, in some cases i have missing weeks in the middle of the dataframe and i want to insert rows to fill in the missing rows as copies of the last existing row, in this case copies of week 8 but with incremental value for the column week : on this table you can see the jump from week 8 to 12
the perfect output would be as follow: the final table with incremental values in column week the correct way
Below is the code i have, it inserted only one row which is 11
for f in range(1, 52 , 1):
if final.iat[i,8]== f and final.iat[i-1,8] != f-1 :
if final.iat[i,8] > final.iat[i-1,8] and final.iat[i,8] != (final.iat[i-1,8] - 1):
line = final.iloc[i-1]
c1 = final[0:i]
c2 = final[i:]
c1.loc[i]=line
concatinated = pd.concat([c1, c2])
concatinated.reset_index(inplace=True)
concatinated.iat[i,11] = concatinated.iat[i-1,11]
concatinated.iat[i,9]= f-1
finaltemp = finaltemp.append(concatinated)```