Linked Questions

Popular Questions

How can I iterate over rows in a Pandas DataFrame?

Asked by At

I have a pandas dataframe, df:

   c1   c2
0  10  100
1  11  110
2  12  120

How do I iterate over the rows of this dataframe? For every row, I want to access its elements (values in cells) by the name of the columns. For example:

for row in df.rows:
    print(row['c1'], row['c2'])

I found a similar question, which suggests using either of these:

  • for date, row in df.T.iteritems():
    
  • for row in df.iterrows():
    

But I do not understand what the row object is and how I can work with it.

Related Questions