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)
As a workaround, you can call
argmaxon the underlying NumPy array: