Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ajcr opened this issue Sep 21, 2015 · 3 comments
Closed
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Nuisance Columns Identifying/Dropping nuisance columns in reductions, groupby.add, DataFrame.apply Reduction Operations sum, mean, min, max, etc.

Comments

@ajcr
Copy link
Contributor

ajcr commented Sep 21, 2015

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
@jorisvandenbossche
Copy link
Member

Yes, that seems like a bug. PR always welcome!

@jreback
Copy link
Contributor

jreback commented Sep 22, 2015

The level arg dispatches to groupby, and because .max/.min handled for strings this 'works'.

So this may require explict filtering before dispatching to handle in a more uniform way. So _make_stat_function might want to do this (or maybe a simpler way)

@jreback jreback added this to the Next Major Release milestone Sep 22, 2015
@jreback jreback added the Dtype Conversions Unexpected or buggy dtype conversions label Sep 22, 2015
@jbrockmendel jbrockmendel added Nuisance Columns Identifying/Dropping nuisance columns in reductions, groupby.add, DataFrame.apply Reduction Operations sum, mean, min, max, etc. labels Sep 22, 2020
@mroeschke
Copy link
Member

The level keyword in aggregation functions was recently deprecated in #40869 so I don't this this bug will be relevant in the future once this keyword is removed. Closing but happy to reopen if I misunderstood anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Nuisance Columns Identifying/Dropping nuisance columns in reductions, groupby.add, DataFrame.apply Reduction Operations sum, mean, min, max, etc.
Projects
None yet
Development

No branches or pull requests

5 participants