QST: When using df.loc[ ] in a for loop I get better performance overall than if I use df.loc() sequentially.
- [x] I have searched the [[pandas] tag](https://stackoverflow.com/questions/tagged/pandas) on StackOverflow for similar questions.

- [ ] I have asked my usage related question on [StackOverflow](https://stackoverflow.com): I am not a StackOverflow user.

---

## Question about pandas

When using df.loc[ ] in a for loop I get better performance overall then if I use df.loc() sequentially.

### Background
I have noticed the following behavior, which is more pronounced with larger DataFrames(). Currently, the "larger" DataFrame() we use is 75,000 rows with 2,100 columns. The DataFrame() is extended an additional 1,000 rows, and so is in total 76,000 rows long (see below). The columns are equally split between,
- int64, float64, and object (a string).

We are pre-loading the DataFrame() with a 1,000 extra rows, which are used for updates instead of resorting to more costly appends. The code I used to look at the performance of updating rows with a list of Series and df.loc[ ] as opposed to using a single row with df.loc[ ] is listed below.

### Behavior Updating Rows

Using update_multiple_rows() I find that,
- mean = 3.0 seconds per row
- maximum time to insert a row = 260 seconds at the first position 75001.

Using 2 repeated calls to update_one_row() I find that,
- For each call the time required for one row to be updated is 260 seconds.

```python
def main():
    df = create_df()  # Returns a large DataFrame().
    test_rows = get_test_rows()  # Gets 100 rows to update the DataFrame() with.
   
    update_multiple_rows(test_rows, 75001)

    update_one_row(test_rows[0], 75001)
    update_one_row(test_rows[0], 75001)


def update_multiple_rows(df: DataFrame, rows: list, index_start: int):
    number_of_rows = len(rows)    
    for i in range(index_start, number_of_rows + 1):
        start = time()
        df.loc[i] = new_row_data
        elapsed = time() - start

def update_one_row(df: DataFrame, row: Series, index: int):
    start = time()
    df.loc[i] = new_row_data
    elapsed = time() - start
```

