pandas: TypeError on argmax of object dtype (change from 0.20.3)

>>> import pandas as pd
>>> pd.Series([0, 0], dtype='object').argmax()

I was doing action = state_action.idxmax() where state_action was of type ‘pandas.core.series.Series’. When I run in 0.21.0, it gives the following error:

File “/usr/local/lib/python3.5/dist-packages/pandas/core/series.py”, line 1357, in idxmax i = nanops.nanargmax(_values_from_object(self), skipna=skipna) File “/usr/local/lib/python3.5/dist-packages/pandas/core/nanops.py”, line 74, in _f raise TypeError(msg.format(name=f.name.replace(‘nan’, ‘’))) TypeError: reduction operation ‘argmax’ not allowed for this dtype

However, when I downgraded to pandas 0.20.3, it worked just fine. You might wanna look into this. 😃

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (12 by maintainers)

Most upvoted comments

As a workaround, you can call argmax on the underlying NumPy array:

Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 27 2017, 12:14:30) 
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> pd.Series(['one', 'two']).values.argmax()
1