title: Looping through pandas' dataframe rows and compare values on columns
body: <p>Many thanks in advance. I am python newbie and this was a bit harder than I thought.</p>
  
  <p>I have an array [m, n] where m are the names of players (0-9) and n are years (A-E). I have marked each row with a "1" signifying if that player was taken into the previous team game ("0" if they were not). I would like to create a few groupings/classes given this.</p>
  
  <pre><code>  A B C D E
  0 1 0 0 1 0
  1 1 0 1 0 0
  2 0 0 1 1 1
  3 1 1 1 1 1
  4 0 1 1 0 0
  5 0 1 1 1 0
  6 1 1 0 1 1
  7 0 0 0 0 1
  8 1 0 1 1 0
  9 1 1 0 1 1
  </code></pre>
  
  <p>Some edits on the classes:
  1. First time in team (a)
  2. Still in tema and been consecutively for past years (b)
  3. Still in team but on and off (c)
  4. Not in team but been there before (d)
  5. Never made it to team (e)</p>
  
  <p>The idea is to have functions for each of the classes that are later compiled into one function.</p>
  
  <p>For example, here is a sample code for Class a:</p>
  
  <pre><code>class_a=[]
  for (i, row) in test.iterrows():
      if (test.iloc[i, -1]==1):
          if (test.iloc[i, 0:-2].sum(axis=0))==0:
              class_a.append('Yes')
  </code></pre>
  
  <p>However, sample code for Class b is a bit more difficult:</p>
  
  <pre><code>test1=[]
  count=0
  
  for (i, row) in test.iterrows():
      row = test.iloc[i, 0:-1]
      for j in range(0, len(row)-1):
          if row[j]&gt;=row[j+1]:
              print(i, row[j], row[j+1], 'Yes')
              count+=1
  print(count)
  </code></pre>
  
  <p>When I print the result of i, row[j] and row[j+1], I get the following values which cannot be right. I am deducing that the interation on the row values is not right as I am missing an index across the rows (the j value). The count seems to be ok (even though is counting the wrong thing):</p>
  
  <pre><code>0 1 0 Yes
  0 0 0 Yes
  1 1 0 Yes
  1 1 0 Yes
  2 0 0 Yes
  2 1 1 Yes
  3 1 1 Yes
  3 1 1 Yes
  3 1 1 Yes
  4 1 1 Yes
  4 1 0 Yes
  5 1 1 Yes
  5 1 1 Yes
  6 1 1 Yes
  6 1 0 Yes
  7 0 0 Yes
  7 0 0 Yes
  7 0 0 Yes
  8 1 0 Yes
  8 1 1 Yes
  9 1 1 Yes
  9 1 0 Yes
  22
  </code></pre>
  
  <p>Any help and pointers are greatly appreciated. I did think of using arrays but it is complicated as the value is on each of the rows, not the columns. Am I thinking wrong? Many thanks!</p>