Skip to content

Fix: Update pivot_table for pandas 2.0+ compatibility#4

Open
blu3-bird wants to merge 2 commits intothepycoach:mainfrom
blu3-bird:aggfunc-issue
Open

Fix: Update pivot_table for pandas 2.0+ compatibility#4
blu3-bird wants to merge 2 commits intothepycoach:mainfrom
blu3-bird:aggfunc-issue

Conversation

@blu3-bird
Copy link

Problem

pivot_table() with aggfunc='sum' fails on pandas 2.0+ when DataFrame contains non-numeric columns.

Solution

Filter to numeric columns before applying pivot_table:

# Before
df_sales.pivot_table(index='Gender', aggfunc='sum').round(1)

# After
numeric_df = df_sales.select_dtypes(include='number')
numeric_df['Gender'] = df_sales['Gender']
numeric_df.pivot_table(index='Gender', aggfunc='sum').round(1)

Fix Issue #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant