title: Tips for faster pandas slicing and column sum calculation
body: <p>I want to improve the comp. performance in different sections of my code and was just wondering how I would go about it in the pandas sections.</p>
  
  <p>E.g., to tackle the sum calculation for certain columns, I compared a few examples based on a small DataFrame</p>
  
  <h2>1)</h2>
  
  <pre><code>%timeit -n 5 -r 1000 df[['week_points', 'month_points', 'dk_avg_points', 'home']].sum(axis=0)
  </code></pre>
  
  <p>5 loops, best of 1000: 911 µs per loop</p>
  
  <h2>2)</h2>
  
  <pre><code>%timeit -n 5 -r 1000 df[['week_points', 'month_points', 'dk_avg_points', 'home']].values.sum(axis=0)
  </code></pre>
  
  <p>5 loops, best of 1000: 716 µs per loop</p>
  
  <h2>3)</h2>
  
  <pre><code>%timeit -n 5 -r 1000 df['week_points'].sum(); df['month_points'].sum(); avg_pts = df['dk_avg_points'].sum(); df['home'].sum() 
  </code></pre>
  
  <p>5 loops, best of 1000: 411 µs per loop</p>
  
  <h2>4)</h2>
  
  <pre><code>%timeit -n 5 -r 1000 df['week_points'].values.sum(); df['month_points'].values.sum(); avg_pts = df['dk_avg_points'].values.sum(); df['home'].values.sum() 
  </code></pre>
  
  <p>5 loops, best of 1000: 17.2 µs per loop</p>
  
  <p>Number 3 &amp; 4 really surprised me. Why would it be so much faster to calculate the sum for every column separately? Do I have an error of thought here, or is there some explanation for this?</p>
  
  <p>And it would also be nice if you have any further ideas to improve the speed for the calculation!
  Thanks!</p>