Adding items to empty pandas DataFrame
<p>I want to dynamically extend an empty pandas DataFrame in the following way:</p>

<pre><code>df=pd.DataFrame()
indices=['A','B','C']
colums=['C1','C2','C3']
for colum in colums:
    for index in indices:
        #df[index,column] = anyValue
</code></pre>

<p>Where both indices and colums can have arbitrary sizes which are not known in advance, i.e. I cannot create a DataFrame with the correct size in advance.</p>

<p>Which pandas function can I use for </p>

<pre><code>#df[index,column] = anyValue
</code></pre>

<p>?</p>

<p><code>loc</code> works very well, but...<br>
For single assignments use <code>at</code></p>

<pre><code>df = pd.DataFrame()
indices = ['A', 'B', 'C']
columns = ['C1', 'C2', 'C3']
for column in columns:
    for index in indices:
        df.at[index, column] = 1

df
</code></pre>

<p><a href="http://i.stack.imgur.com/MHVHZ.png" rel="nofollow"><img src="http://i.stack.imgur.com/MHVHZ.png" alt="enter image description here"></a></p>

<hr>

<h1><code>.at</code> vs <code>.loc</code> vs <code>.set_value</code> timing</h1>

<p><a href="http://i.stack.imgur.com/wuE0T.png" rel="nofollow"><img src="http://i.stack.imgur.com/wuE0T.png" alt="enter image description here"></a></p>

python pandas