title: Surprisingly slow access to elements of DataFrame
body: <p>Consider following example</p>
  <pre class="lang-py prettyprint-override"><code>x = {f&quot;b{k}&quot;:10000*[None] for k in range(10)}
  for column in x.keys():
      for i in range(10000):
          x[column][i] = i % 4 # some minor calculation here
  x = pd.DataFrame(x)
  </code></pre>
  <p>It finishes in about 60ms on my computer. Similar thing can be done on Pandas's DataFrame directly:</p>
  <pre class="lang-py prettyprint-override"><code>x = pd.DataFrame(index=range(10000), columns=[f&quot;b{i}&quot; for i in range(10)], dtype=np.int32)
  for column in x.columns:
      for i in range(10000):
          x.loc[i, column] = i % 4 # some minor calculation here
  </code></pre>
  <p>This snippet finishes in about 11.8s. Can this kind of operation be done directly on the DataFrame without a significant performance hit?</p>
  <p><strong>Update</strong>:</p>
  <p>Using <code>.at</code> instead of <code>.loc</code> <a href="http://pandas-docs.github.io/pandas-docs-travis/user_guide/indexing.html#fast-scalar-value-getting-and-setting" rel="nofollow noreferrer">as suggested in the Pandas docs</a> improves things considerably but still significantly slower compared to Python's dict.</p>
  <pre><code>x = pd.DataFrame(index=range(10000), columns=[f&quot;b{i}&quot; for i in range(10)], dtype=np.int32)
  for column in x.columns:
      for i in range(10000):
          x.at[i, column] = i % 4
  </code></pre>
  <p>This finishes in about 1.2s.</p>