From 4d0b13262177210dd4bd619451280f2d9fc4989e Mon Sep 17 00:00:00 2001 From: Jihwan Song Date: Thu, 18 Jun 2020 14:46:05 -0400 Subject: [PATCH] to speed up rendering of styler see https://github.com/pandas-dev/pandas/issues/19917 --- pandas/io/formats/style.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index f7ba4750bc2ad..1abe64735dc03 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -561,11 +561,15 @@ def _update_ctx(self, attrs: DataFrame) -> None: Whitespace shouldn't matter and the final trailing ';' shouldn't matter. """ - for row_label, v in attrs.iterrows(): - for col_label, col in v.items(): - i = self.index.get_indexer([row_label])[0] - j = self.columns.get_indexer([col_label])[0] - for pair in col.rstrip(";").split(";"): + rows = [(row_label, v) for row_label, v in attrs.iterrows()] + row_idx = self.index.get_indexer([x[0] for x in rows]) + for ii, row in enumerate(rows): + i = row_idx[ii] + cols = [(col_label, col) for col_label, col in row[1].items() if col] + col_idx = self.columns.get_indexer([x[0] for x in cols]) + for jj, itm in enumerate(cols): + j = col_idx[jj] + for pair in itm[1].rstrip(";").split(";"): self.ctx[(i, j)].append(pair) def _copy(self, deepcopy: bool = False) -> "Styler":