Get startedGet started for free

Iterating with .iterrows()

In the video, we discussed that .iterrows() returns each DataFrame row as a tuple of (index, pandas Series) pairs. But, what does this mean? Let's explore with a few coding exercises.

A pandas DataFrame has been loaded into your session called pit_df. This DataFrame contains the stats for the Major League Baseball team named the Pittsburgh Pirates (abbreviated as 'PIT') from the year 2008 to the year 2012. It has been printed into your console for convenience.

This exercise is part of the course

Writing Efficient Python Code

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Iterate over pit_df and print each row
for ____,____ in ____.____:
    print(row)
Edit and Run Code