Skip to content

Commit cea7a2b

Browse files
committed
Descriptive error message on when the dataframe is empty and margin is set
1 parent ea75dd7 commit cea7a2b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

pandas/core/reshape/pivot.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,9 @@ def _normalize(
11651165

11661166
elif margins is True:
11671167
# keep index and column of pivoted table
1168+
if table.empty:
1169+
raise ValueError("Can't get margins since the result dataframe is empty ")
1170+
11681171
table_index = table.index
11691172
table_columns = table.columns
11701173
last_ind_or_col = table.iloc[-1, :].name

0 commit comments

Comments
 (0)