title: How to computer percentages and accumulated percentages with pandas
body: <p>I'm calculating from drivers that are involved in accidents, what percentage are in each age group, and accumulated percentage (for example drivers till age 39 are involved in 50% of all accidents)</p>
  
  <p>The code below works, but I'm sure there is a more concise/efficient/clear way of doing this.</p>
  
  <pre><code>df = pd.DataFrame({'Age group': ['20-29','30-39','40-49','50-59','60 and up'], 
                     'Number accidents': [10000, 8000, 6000, 3000, 1000]})
  num_accidents = sum(df['Number accidents'])
  df['% accidents'] = df['Number accidents'] / num_accidents * 100
  per_acc = 0
  for i in df.index:
      per_acc += df.loc[i,'% accidents']
      df.loc[i,'% accidents accumulated'] = per_acc
  df
  </code></pre>
  
  <p>Following is the output of the code above.  </p>
  
  <pre><code>   Age group  Number accidents  % accidents  % accidents accumulated
  0      20-29             10000    35.714286                35.714286
  1      30-39              8000    28.571429                64.285714
  2      40-49              6000    21.428571                85.714286
  3      50-59              3000    10.714286                96.428571
  4  60 and up              1000     3.571429               100.000000
  </code></pre>
  
  <p>Please help with a better way to write it</p>