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)