As change the method by make grouping all the NAN fields with year ,month and week and it will work.
df['week'] = df['day'].apply(lambda x: (x - 1) // 7 + 1) # Assign week numbers
df['C'] = df.groupby(['year', 'month', 'week'])['C'].transform(lambda x: x.ffill().bfill())