I am trying to loop through a pandas data frame and replace values in certain columns if they meet certain conditions. I realize there are more straightforward ways to do this in general, but in my specific example I need a loop because the result for one row can depend on the prior row. Below is a reproducible example of what is going wrong. When I try to replace text it does not replace it.
import pandas as pd
df = pd.DataFrame({"A": ["I", "AM", "NOT", "WORKING", "!"], "B": [20, 30, 10, 40, 50], "C": [32, 234, 23, 23, 42523]})
for index, row in df.iterrows():
row['A'] = "I am working!"
print(df)
Which prints:
A B C
0 I 20 32
1 AM 30 234
2 NOT 10 23
3 WORKING 40 23
4 ! 50 42523