Modifing data while using iterrows() does not work

The code doesn’t work because: (source)

Depending on the data types, the iterator returns a copy and not a view, and writing to it will have no effect.

To write to it, you can try to see if at works, i.e.,

for x,y in data.iterrows():
    if y['num_wings'] in [10,45]:
        data.at[x, 'num_wings'] = 50

Just modifying something while you’re iterating over it is not recommended. But I think it should be OK in your case.

Leave a Comment