Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crosstab(aggfunc='skew') bug #60883

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pandas/core/reshape/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,10 @@ def _normalize(
# keep index and column of pivoted table
table_index = table.index
table_columns = table.columns

if table.empty:
return table

last_ind_or_col = table.iloc[-1, :].name

# check if margin name is not in (for MI cases) and not equal to last
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/reshape/test_crosstab.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,3 +877,17 @@ def test_categoricals(a_dtype, b_dtype):
expected = expected.loc[[0, 2, "All"]]
expected["All"] = expected["All"].astype("int64")
tm.assert_frame_equal(result, expected)

def test_crosstab_aggfunc_skew():
# Test case for crosstab with aggfunc='skew'
result = crosstab(
index=["index1", "index2"],
columns=["one", "one"],
values=[12, 10],
normalize=1,
margins=True,
dropna=True,
aggfunc='skew'
)
assert isinstance(result, DataFrame)
assert not result.empty
Loading