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.
Deze oefening maakt deel uit van de cursus
Writing Efficient Python Code
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Iterate over pit_df and print each row
for ____,____ in ____.____:
print(row)