Skip to content

Sparse data frame doesn't groupby.mean() correctly #5078

Closed
@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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions