wwl
wwl

Reputation: 2065

Iterating through iterrows

iterrows can be used to iterate through a pandas dataframe:

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

How can I use a second for loop to iterate through each element in the row?

Upvotes: 0

Views: 1672

Answers (1)

wwl
wwl

Reputation: 2065

iterrows returns a tuple. The element indexed by [1] contains the row. You can then iterate through that element.

for row in x.iterrows():
    print(row[1])
    for b in row[1]:
        print(b)

Upvotes: 1

Related Questions