Skip to main content
Fixed the question formation - missing auxiliary (or helping) verb - see e.g. <https://www.youtube.com/watch?v=t4yWEt0OSpg&t=1m49s> (see also <https://www.youtube.com/watch?v=kS5NfSzXfrI> (QUASM)) - alternatively, drop the question mark.
Link
Peter Mortensen
  • 31.2k
  • 22
  • 111
  • 134

How tocan I iterate over rows in a Pandas DataFrame?

improve title
Link
Rob Bednark
  • 28.9k
  • 28
  • 90
  • 131

How to iterate over rows in a DataFrame in Pandas DataFrame?

improve format
Source Link
cottontail
  • 26.3k
  • 26
  • 196
  • 182

I have a pandas dataframe, df:

   c1   c2
0  10  100
1  11  110
2  12  120
   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 be able 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():
  • 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.

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 be able 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.

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.

Shorten.
Source Link
Mateen Ulhaq
  • 28k
  • 22
  • 122
  • 157
Loading
edited tags
Link
coldspeed95
  • 406.9k
  • 106
  • 746
  • 799
Loading
Rollback to Revision 7
Link
coldspeed95
  • 406.9k
  • 106
  • 746
  • 799
Loading
Improving question title (better definition).
Link
ivanleoncz
  • 10.3k
  • 7
  • 64
  • 53
Loading
Rollback to Revision 5
Link
ead
  • 34.8k
  • 8
  • 103
  • 172
Loading
edited tags
Link
JohnE
  • 30.7k
  • 9
  • 87
  • 116
Loading
Notice removed Reward existing answer by jezrael
Bounty Ended with coldspeed95's answer chosen by jezrael
Notice added Reward existing answer by jezrael
Bounty Started worth 100 reputation by jezrael
Active reading [<https://en.wikipedia.org/wiki/Pandas_%28software%29>].
Source Link
Peter Mortensen
  • 31.2k
  • 22
  • 111
  • 134
Loading
Post Merged (destination) from stackoverflow.com/questions/10729210/…
Question Protected by Serenity
deleted 45 characters in body
Source Link
petezurich
  • 10.3k
  • 10
  • 48
  • 63
Loading
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot
Loading
edited title
Link
tumultous_rooster
  • 12.7k
  • 34
  • 97
  • 157
Loading
Source Link
Roman
  • 132.4k
  • 174
  • 370
  • 468
Loading