Creating a pandas dataframe by adding columns
<p>Is there a way to create a dataframe by adding individual columns? </p>

<p>Following is my code snippet:</p>

<pre><code>df=pandas.DataFrame()
for key in matrix:
    for beta in matrix[key]:
        df[key] = matrix[key][beta]
print(df)
</code></pre>

<p>As you can see that I start by creating an empty dataframe and then as my loop iterates, I am attempting to add a new column. 
This adds the column names but doesn't add values to the rows.</p>

<p><strong>Note</strong> matrix is a multi-level hash   </p>

<pre><code> {'ABC10059536': {'577908224': '0.5902'},
  'ABC10799208': {'577908224': '0.369'},
  'ABC12564102': {'577908224': '0.163'},
  'ABC17441804': {'577908224': '0.4233'},
  'ABC20764275': {'577908224': '0.349'},
  'ABC21090866': {'577908224': '0.4704'}}
</code></pre>

<p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html" rel="nofollow"><code>DataFrame</code></a> constructor:</p>

<pre><code>d = {'ABC10059536': {'577908224': '0.5902'},
  'ABC10799208': {'577908224': '0.369'},
  'ABC12564102': {'577908224': '0.163'},
  'ABC17441804': {'577908224': '0.4233'},
  'ABC20764275': {'577908224': '0.349'},
  'ABC21090866': {'577908224': '0.4704'}}

df = pd.DataFrame(d) 
print (df)  
          ABC10059536 ABC10799208 ABC12564102 ABC17441804 ABC20764275  \
577908224      0.5902       0.369       0.163      0.4233       0.349   

          ABC21090866  
577908224      0.4704  
</code></pre>

python pandas dataframe