我相信最近版本的更改会导致对 idxmax() 的调用在以前可以工作的情况下失败。我并不是说这是一种回归,我只是试图理解原因和正确的问题调用。
type(sss)
<class 'pandas.core.series.Series'>
sss.dtype
dtype('O')
type(sss.index)
<class 'pandas.core.indexes.base.Index'>
sss.index=Index([...strings.., dtype'object', length=112)
该系列中的单列具有包含许多 NaN 的数字类型,以及一些有效数字。 所有索引都是字符串。 我正在搜索列最大值的索引。
我怎样才能获得它?
最佳答案
我无法在 pandas 0.19.2 上复制。您可以转换为float
,然后使用pd.Series.idxmax
:
df = pd.DataFrame({'A': [0, 1.5, 1.0, np.nan, np.nan, 54, 19, np.nan]}, dtype=object,
index=list('abcdefgh'))
res = df['A'].astype(float).idxmax() # 'f'
关于python - 当 dtype 为 dtype ('O' 时,pandas 系列 idxmax() 失败),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49759346/