Skip to content

Fix: Update pivot_table for pandas 2.0+ compatibility - #4

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

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

Conversation

@blu3-bird

Copy link
Copy Markdown

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