This is an archived version of the course and is no longer updated. Please find the latest version of the course on the main webpage.

DataFrame iterations

Iterating over columns

Iterating over a DataFrame object gives you the column names

for col in df:
    print(col)

## Rank
## Genre
## Description
## Director
## Actors
## Year
## Runtime (Minutes)
## Rating
## Votes
## Revenue (Millions)
## Metascore

Iterating over rows

To iterate over rows, you have several choices: .iteritems(), .iterrows(), .itertuples().

Try to figure out what the difference between these three choices are!

for (key, value) in df.iteritems():
    print(key, value)

for (row_index, row) in df.iterrows():
    print(row_index, row)

for row in df.itertuples():
    print(row)