title: PANDAS count on condition
body: <p>I am trying to tabulate a change in condition using a 'groupby' but am stumped and would appreciate any guidance. I have a data frame as follows:</p>
  
  <pre><code>SUBJECT    TYPE
  1          1
  1          2
  1          2
  2          1
  2          1
  3          1
  3          3
  3          5
  </code></pre>
  
  <p>I would like to generate a statement that tabulates any positive change, ignores any negative change, and generates a count of change per subject. For example, the output of the above would be:</p>
  
  <pre><code>Subject    TYPE
  1          1
  2          0
  3          2
  </code></pre>
  
  <p>Would I need create an if/else clause using pandas, or is there a simpler way to achieve this using summit? Maybe something like...</p>
  
  <pre><code>def tabchange(type, subject):
      current_subject = subject[0]
      type_diff = type - type
      j = 1
      for i in range(1,len(type)):
          type_diff[i] = type[i] - type[i-j]
          if subject[i] == current_subject:
              if type_diff[i] &gt; 0:
                  new_row = 1
                  j += 1
              else:
                  j = 1
          else: 
              new_row[i] = 0
              current_subject = subject[i]
      return new_row
  </code></pre>