Skip to content

BUG: strange behaviour in quantile with group by #33569

@abdullahodibat

Description

@abdullahodibat

is this a bug in pandas? why null values in the grouped by field break the quantile?

df = pd.DataFrame({ 'category': ['A', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B', 'B'], 'value': [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6] }) quantiles = df.groupby('category')['value'].quantile(0.75) print(quantiles) df2 = pd.DataFrame({ 'category': ['A', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B', 'B', np.nan], 'value': [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6,1] }) quantiles2 = df2.groupby('category')['value'].quantile(0.75) print(quantiles2) 

produces this output:

category A 4.75 B 4.75 Name: value, dtype: float64 category A 3.75 B 3.75 Name: value, dtype: float64 

im using pandas 1.0.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions