I have the dataset for covid tests in Ireland. In May the data just stops.


To continue the trend, I took the average mon-sun during the last stable period. So I have 7 different mean values.

Now I want to edit the dataset to insert these values in sequence from the row indexed '47545'.

I don't get any error and it doesn't change the dataset.

ireland_df3 = ireland_df.copy()

ireland_df3[ireland_df3.reset_index().index % 7 == 47545]['new_tests_per_thousand'] = df1_mean
ireland_df3[ireland_df3.reset_index().index % 7 == 47546]['new_tests_per_thousand'] = df2_mean
ireland_df3[ireland_df3.reset_index().index % 7 == 47547]['new_tests_per_thousand'] = df3_mean
ireland_df3[ireland_df3.reset_index().index % 7 == 47548]['new_tests_per_thousand'] = df4_mean
ireland_df3[ireland_df3.reset_index().index % 7 == 47549]['new_tests_per_thousand'] = df5_mean
ireland_df3[ireland_df3.reset_index().index % 7 == 47550]['new_tests_per_thousand'] = df6_mean
ireland_df3[ireland_df3.reset_index().index % 7 == 47551]['new_tests_per_thousand'] = df7_mean

Any ideas?

  • $\begingroup$ What you actually do is to create a modified copy. Use iloc or loc to change the actual data as it has been answered. $\endgroup$
    – rapaio
    Commented Sep 27, 2021 at 12:23

1 Answer 1


Try loc or iloc, such as:

ireland_df3.iloc[47545, 'new_tests_per_thousand'] = df1_mean  

and so on

What do you want to do with the operations in the brackets? As it is now it looks like it checks if mod 7 of the index equals 47545? which does not make sense.

  • $\begingroup$ I need to edit all the rows after that row. The code in brackets is trying to edit every seventh row with that value. So from row 47545 it starts to to update the dataset with this sequence of seven values. $\endgroup$
    – GethLife
    Commented Sep 27, 2021 at 17:56
  • $\begingroup$ So you want the 47545th value equals 47552, 47559 and similarly for the rest?? You can do that by setting an iterable, let's say i=0, set the row indexer to be 47545 + i%7, and increase by one in each loop $\endgroup$
    – serali
    Commented Sep 27, 2021 at 18:08
  • $\begingroup$ thanks. do you have an example of that please? $\endgroup$
    – GethLife
    Commented Sep 27, 2021 at 18:59
  • $\begingroup$ ireland_df3 = ireland_df.copy() for i in ireland_df3.iterrows(): #print(ireland_df3[i]) if ireland_df3[i][0] >= 47545: ireland_df3.iloc[i][9] = random.choices(meanList) $\endgroup$
    – GethLife
    Commented Sep 30, 2021 at 11:11
  • $\begingroup$ this doesnt work. $\endgroup$
    – GethLife
    Commented Sep 30, 2021 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.