title: calculating running totals in separate columns in Pandas DF
body: <p>I have a pandas dataframe like this.</p>
  
  <pre><code>frame =  pd.DataFrame({'home' : ['CHI', 'ATL', 'SEA', 'DET', 'STL','HOU' ,'CHI','CHI'],
                     'away' : ['DET', 'CHI', 'HOU', 'TOR', 'DAL', 'STL', 'MIA', 'SEA']})
  </code></pre>
  
  <p>Thanks to <strong>unutbu</strong> I can keep a running total of total games played for each team like this.</p>
  
  <pre><code>awayGP = collections.Counter()
  homeGP = collections.Counter()
  
  def count_games():
      for idx, row in frame.iterrows():
          homeGP[row['home']] +=1
          awayGP[row['away']] +=1
          test = homeGP + awayGP
          yield awayGP[row['away']], awayGP[row['home']], , homeGP[row['away']], homeGP[row['home']]
  
  frame['awayteamAwayGP'] , frame['hometeamAwayGP'], frame['awayteamHomeGP'],          frame['hometeamHomeGP'] = zip(*list(count_games()))                                                             
  frame['awayteamGames'] =   frame['awayteamAwayGP'] + frame['awayteamHomeGP']                                                                                       
  frame['hometeamGames'] =   frame['hometeamAwayGP'] + frame['hometeamHomeGP']        
  del frame['awayteamAwayGP'] , frame['hometeamAwayGP'], frame['awayteamHomeGP'],    frame['hometeamHomeGP']  
  </code></pre>
  
  <p>I would like to be able to keep running total of the points scored for each team.</p>
  
  <pre><code>frame['awayPTS'] = [88, 75, 105, 99, 110, 85, 95, 100]
  frame['homePTS'] = [92, 88, 95, 97, 100, 74, 98, 110]
  </code></pre>
  
  <p>This is the desired output.</p>
  
  <pre><code>away  home  awayteamGP  hometeamGP awayPTS  homePTS awayteam_totalPTS hometeam_totalPTS 
   DET   CHI     1             1       88        92          88               92
   CHI   ATL     2             1       75        88          180              88
   HOU   SEA     1             1       105       95          105              95
   TOR   DET     1             2       99        97          99               187
   DAL   STL     1             1       110       100         110              100
   STL   HOU     2             2       85        74          185              179
   MIA   CHI     1             3       95        98          95               265
   SEA   CHI     2             4       100       110         195              375
  </code></pre>