IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Writing Efficient Python Code

Visualizza il corso

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Iterate over pit_df and print each row
for ____,____ in ____.____:
    print(row)
Modifica ed esegui il codice