Skip to content

Inconsistent mean over booleans #8734

Closed
@vladfi1

Description

@vladfi1

It appears that the mean aggregate function is inconsistent when operating on boolean values.

from pandas import DataFrame

df1 = DataFrame({'a': [1, 1], 'bools': [True, True]})
df2 = DataFrame({'a': [1, 1], 'bools': [True, False]})

print df1.mean().bools # 1.0
print df2.mean().bools # 0.5

print df1.groupby('a').mean() # DataFrame with 1: True
print df2.groupby('a').mean() # DataFrame with 1: 0.5

For some reason the mean of a set of True values is True instead of 1.0, but only for GroupBy objects and not for DataFrame objects.

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