Skip to content

Passing a level argument to max/min prevents non-numeric columns from being dropped #11164

Closed
@ajcr

Description

@ajcr

When passing a level argument and numeric_only=True to max and min, non-numeric columns are not dropped in the result:

>>> df = pd.DataFrame({'a': [1,1,2,2], 'b': [1,4,2,6], 
                       'c': [6,3,2,3], 'd': ['w','x','y','z']})
>>> df.set_index(['a', 'b'])
>>> df
     c  d
a b      
1 1  6  w
  4  3  x
2 2  2  y
  6  3  z

>>> df.max(level=0, numeric_only=True)
   c  d
a      
1  6  x
2  3  z

I would have expected that column 'd' would not be included here, as is the case if the level argument is omitted:

>>> df.max(numeric_only=True)
c    6
dtype: int64

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsNuisance ColumnsIdentifying/Dropping nuisance columns in reductions, groupby.add, DataFrame.applyReduction Operationssum, mean, min, max, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions