Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • 14
    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). Commented Apr 4, 2018 at 13:44
  • @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. Commented Sep 18, 2023 at 22:58