Timeline for answer to How can I iterate over rows in a Pandas DataFrame? by cheekybastard
Current License: CC BY-SA 4.0
Post Revisions
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 20 at 0:17 | history | edited | Peter Mortensen | CC BY-SA 4.0 |
Expanded.
|
| Sep 18, 2023 at 22:58 | comment | added | Gabriel Staples |
@gented, that's not exactly true. To get access to values in a previous row, for instance, you can simply add a new column containing previous-row values, like this: dataframe["val_previous"] = dataframe["val"].shift(1). Then, you could access this val_previous variable in a given row using this answer.
|
|
| Sep 18, 2023 at 22:55 | history | edited | Gabriel Staples | CC BY-SA 4.0 |
added 132 characters in body
|
| Apr 3, 2023 at 5:45 | review | Suggested edits | |||
| Apr 5, 2023 at 0:09 | |||||
| Apr 4, 2018 at 13:44 | comment | added | gented |
Notice that apply doesn't "iteratite" over rows, rather it applies a function row-wise. The above code wouldn't work if you really do need iterations and indeces, for instance when comparing values across different rows (in that case you can do nothing but iterating).
|
|
| Jun 1, 2015 at 6:24 | history | answered | cheekybastard | CC BY-SA 3.0 |