title: Fast pandas.DataFrame initialization
body: <h1>Question</h1>
  
  <p>What is an efficient way to get the following pandas DataFrame? (Update: numbers change each time)</p>
  
  <pre><code>   alpha  beta  gamma
  0    1.5   2.5    3.5
  
  [1 rows x 3 columns]
  </code></pre>
  
  <h2>Motivation</h2>
  
  <p>I added a pandas.DataFrame API to some of my methods be able to do calculations in batches.</p>
  
  <p>When replicating some of my testcases for the new API the execution of my testbenches raised from 200ms to over 8 seconds. Doing a profile run, I noticed that the main cause is creating 20k <code>pandas.DataFrame</code> objects.</p>
  
  <p>See the comparison</p>
  
  <pre><code>In [1]: import pandas as pd
  
  In [2]: timeit pd.DataFrame({'alpha': 1.5, 'beta': 2.5, 'gamma': 3.5}, [0])
  1000 loops, best of 3: 405 us per loop
  
  In [3]: timeit {'alpha': 1.5, 'beta': 2.5, 'gamma': 3.5}
  1000000 loops, best of 3: 200 ns per loop
  </code></pre>
  
  <p>It seems that creating a DataFrame object is 2000 times slower than lower level structures. I tried to optimize it, but this is as fast as I got:</p>
  
  <pre><code>In [4]: import numpy as np
  
  In [5]: timeit pd.DataFrame(np.array([[1.5, 2.5, 3.5]]), columns=['alpha', 'beta', 'gamma'])
  1000 loops, best of 3: 144 us per loop
  </code></pre>
  
  <p>This is still 720 times slower than the dict. Is it possible to be faster? Creating numpy arrays is e.g. only 10 times slower:</p>
  
  <pre><code>In [6]: timeit np.array([[1.5, 2.5, 3.5]])
  100000 loops, best of 3: 1.99 us per loop
  </code></pre>