Python: Looping through a DataFrame with conditions causing unexpected skips
I'm confused about I've hit a wall trying to I'm converting an old project and I'm integrating two systems and I'm currently working with a Pandas DataFrame in Python 3.10, and I'm trying to loop through it to apply some conditions for data transformation... However, I'm running into an scenario where some rows seem to be skipped during the iteration, which is affecting my results. Here's a simplified version of my code: ```python import pandas as pd data = { 'A': [1, 2, 3, 4], 'B': [10, 20, 30, 40], 'C': [1, 1, 0, 0] } df = pd.DataFrame(data) for index, row in df.iterrows(): if row['C'] == 0: df.at[index, 'B'] += 5 df.at[index, 'A'] = row['A'] * 10 ``` After running this loop, I expected the `B` and `A` values to be updated for the rows where `C` is 0, but I found that the changes aren't reflecting as anticipated. In fact, only the first row was updated, and I need to figure out why the loop isn't handling the other rows as expected. I've tried using `df.loc` instead of `df.at`, but that didn't resolve the scenario. I also considered whether the iteration method might be an scenario, but I believe `iterrows()` is standard for this use case. To debug, I printed out the row values inside the loop, and they seem to be correct. Is there something about modifying the DataFrame during iteration that I'm missing? How can I ensure that all relevant rows are processed correctly? I've been using Python for about a year now. This is happening in both development and production on CentOS. What am I doing wrong? This is part of a larger web app I'm building. Thanks, I really appreciate it! What am I doing wrong?