Pandas: iteratively concatenate columns stored in a dictionary of dataframes
<p>Suppose I have a dictionary of <code>pandas</code> dataframes where the keys are <code>0, 1, 2, ..., 999</code>, and the values are dataframes like this (<code>test_df</code>):</p>

<pre><code>          A         B         C
0  1.438161 -0.210454 -1.983704
1 -0.283780 -0.371773  0.017580
2  0.552564 -0.610548  0.257276
3  1.931332  0.649179 -1.349062
4  1.656010 -1.373263  1.333079
5  0.944862 -0.657849  1.526811
</code></pre>

<p>Say that the index means nothing to you, and that you want to create a new dataframe where columns <code>A</code> and <code>B</code> are concatenated:</p>

<p><code>mydf=pd.concat([test_df[0]['A'],test_df[0]['B']], axis=1, keys=['A','B'])</code></p>

<p>Now, <strong>can I use this line inside a for loop which iterates over all the keys in my dictionary of dataframes?</strong> </p>

<p>If not, what would be another way of doing this? The result would be a dataframe with two columns, <code>A</code> and <code>B</code>, and <code>6x1000</code> rows. The index column would therefore go from <code>0</code> to <code>5999</code>.</p>