Pandas Examples: Looping over Dataframe Rows
Last updated:Table of Contents
- Itertuples
- Iterrows
- Iterate and save into variables
- Using apply
- Using map
- Vectorization
- Parallel processing
- Itertuples VS iterrows
All tests done under pandas v1.3.x, under Python 3.8
WIP Alert This is a work in progress. Current information is correct but more content may be added in the future.
HEADS-UP: Prefer vectorization over iteration if you can
Itertuples
TODO
Iterrows
TODO
Iterate and save into variables
TODO save into variables with the same name as the columns.
Using apply
TODO
Using map
TODO
Vectorization
TODO
Parallel processing
TODO
Itertuples VS iterrows
itertuples
is much faster than iterrows
itertuples
is MUCH faster than iterrows
. In this example, processing a dataframe with 100,000 rows was 20 times faster with
itertuples