Sparse data frame doesn't groupby.mean() correctly · Issue #5078 · pandas-dev/pandas (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@langmore

Description

@langmore

import pandas as pd pd.version '0.12.0-660-gec77315'

import numpy as np np.version.version '1.7.1'

df = pd.DataFrame({'a': [0, 1, 0, 0], 'b': [0, 1, 0, 0]}) sdf = df.to_sparse(fill_value=0) df.groupby('a').mean() b a
0 0 1 1

sdf.groupby('a').mean() b a
1 0

I'm not surpised that the mean for group a == 0 was not returned. It is surprising that the result for group a == 1 was incorrect.