How to Iterate Over Rows in pandas, and Why You Shouldn’t
![](https://www.deeplearningdaily.com/wp-content/uploads/2023/01/how-to-iterate-over-rows-in-pandas-and-why-you-shouldnt_63d802b20eb3b-375x210.jpeg)
One of the most common questions you might have when entering the world of pandas is how to iterate over rows in a pandas DataFrame. If you’ve gotten comfortable using loops in core Python, then this is a perfectly natural question to ask.
While iterating over rows is relatively straightforward with .itertuples()
or .iterrows()
, that doesn’t necessarily mean iteration is the best way to work with DataFrames. In fact, while iteration may be a quick way to make progress, relying on iteration can become a significant roadblock when it comes to being effective with pandas.
In this tutorial, you’ll learn how to iterate over the rows in a pandas DataFrame, but you’ll also learn