Skip to content

Commit 5f88c22

Browse files
BUG: Fix Empty DataFrame.style.render raises IndexError
Fix attempt for Issue pandas-dev#15953 Handles DataFrames and Series with no rows or columns using `pd.DataFrame().empty` or `pd.Series().empty`
1 parent 838e09c commit 5f88c22

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pandas/formats/style.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ def format_attr(pair):
218218

219219
cell_context = dict()
220220

221-
n_rlvls = self.data.index.nlevels
222-
n_clvls = self.data.columns.nlevels
221+
n_rlvls = 0 if self.data.empty else self.data.index.nlevels
222+
n_clvls = 0 if self.data.empty else self.data.columns.nlevels
223223
rlabels = self.data.index.tolist()
224224
clabels = self.data.columns.tolist()
225225

0 commit comments

Comments
 (0)