<p dir="auto">When creating html with <code class="notranslate">df.style</code> e.g.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="df.style.apply(color_f, axis=1).render()"><pre class="notranslate"><span class="pl-s1">df</span>.<span class="pl-s1">style</span>.<span class="pl-en">apply</span>(<span class="pl-s1">color_f</span>, <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>).<span class="pl-en">render</span>()</pre></div>
<p dir="auto">pandas assigns to each html cell of the table a unique css class. This means huge html are created, while it would be possible to use the same class for cell with the same style.</p>
<details>
<hr>
<p dir="auto">commit: None<br>
python: 2.7.14.final.0<br>
python-bits: 64<br>
OS: Linux<br>
OS-release: 4.15.14-300.fc27.x86_64<br>
machine: x86_64<br>
processor: x86_64<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: it_IT.UTF-8<br>
LOCALE: None.None</p>
<p dir="auto">pandas: 0.22.0<br>
pytest: 3.1.3<br>
pip: 9.0.1<br>
setuptools: 36.0.1<br>
Cython: 0.27.3<br>
numpy: 1.14.2<br>
scipy: 1.0.0<br>
pyarrow: None<br>
xarray: None<br>
IPython: 5.4.1<br>
sphinx: None<br>
patsy: 0.4.1<br>
dateutil: 2.7.2<br>
pytz: 2018.4<br>
blosc: None<br>
bottleneck: 1.2.1<br>
tables: 3.4.2<br>
numexpr: 2.6.2<br>
feather: None<br>
matplotlib: 2.0.2<br>
openpyxl: None<br>
xlrd: 1.0.0<br>
xlwt: 1.1.2<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: 4.6.0<br>
html5lib: 0.9999999<br>
sqlalchemy: 1.1.11<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.9.6<br>
s3fs: None<br>
fastparquet: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">I am working on a financial simulation (<a href="https://github.com/MartinPyka/financial_life">financial_life</a>), in which I would like to collect my timeseries data in a DataFrame during simulation. However, while looking through several posts on StackOverflow and experimenting with timeit, I noticed that appending data to a Dataframe (e.g. via append or via loc-expansion) is far more inefficient than the append-function for a simple list and then transforming everything to a dataframe, if requested. The latter one is, what I am doing now.</p>
<p dir="auto">So I was wondering, whether there is any performant way of creating a DataFrame in an iterative manner?</p>