Python:查找系列的最大值(从数据帧生成)

Python:查找系列的最大值(从数据帧生成),python,pandas,Python,Pandas,我不知道为什么我找不到系列的最大值。有人能帮忙吗?它是从数据帧生成的 temp Out[190]: 0 0 1 0.0197017 2 0.0183603 3 0.0483337 4 0.0136385 8187 0.0800631 8188 0.0433753 8189 0.0673788 8190 0.0511651 8191 0.0811448 Name: adjr2, Lengt

我不知道为什么我找不到系列的最大值。有人能帮忙吗?它是从数据帧生成的

temp
Out[190]: 
0               0
1       0.0197017
2       0.0183603
3       0.0483337
4       0.0136385

8187    0.0800631
8188    0.0433753
8189    0.0673788
8190    0.0511651
8191    0.0811448
Name: adjr2, Length: 8192, dtype: object

type(temp)
Out[191]: pandas.core.series.Series

temp.idxmax(axis = 1 , skipna=True)
这将显示一条错误消息:

Traceback (most recent call last):

  File "<ipython-input-192-21f0a425e80d>", line 1, in <module>
    temp.idxmax(axis = 1 , skipna=True)

  File "/Users/miao/opt/anaconda3/lib/python3.7/site-packages/pandas/core/series.py", line 2277, in idxmax
    i = nanops.nanargmax(com.values_from_object(self), skipna=skipna)

  File "/Users/miao/opt/anaconda3/lib/python3.7/site-packages/pandas/core/nanops.py", line 67, in _f
    raise TypeError(msg.format(name=f.__name__.replace("nan", "")))

TypeError: reduction operation 'argmax' not allowed for this dtype
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
温度idxmax(轴=1,skipna=True)
idxmax中的文件“/Users/miao/opt/anaconda3/lib/python3.7/site packages/pandas/core/series.py”,第2277行
i=nanops.nanargmax(com.values来自对象(self),skipna=skipna)
文件“/Users/miao/opt/anaconda3/lib/python3.7/site packages/pandas/core/nanops.py”,第67行,in\u f
raise TypeError(msg.format(name=f.uuuuu name_uuuuuuuu.replace(“nan”,“”)))
TypeError:此数据类型不允许还原操作“argmax”

通过以下方式将
系列
转换为数字:

或者,如果某些非数值与
errors='concurve'
一起使用,将它们转换为缺少的值
NaN
s:

pd.to_numeric(temp, errors='coerce').idxmax(axis = 1 , skipna=True)

通过以下方式将
系列
转换为数字:

或者,如果某些非数值与
errors='concurve'
一起使用,将它们转换为缺少的值
NaN
s:

pd.to_numeric(temp, errors='coerce').idxmax(axis = 1 , skipna=True)

pandas中的许多聚合函数(如max)不支持对非数字类型(如
string
object
)的操作。您可以尝试将数据转换为数字类型(这也将提高大型数据集的性能)

您可以使用
temp.astype
转换序列

[47]中的
:s
出[47]:
a 1
b 2
C3
名称:0,数据类型:对象
In[48]:s.astype(float)
出[48]:
a 1
b 2
C3
名称:0,数据类型:float64
在[50]中:s.astype(float.idxmax()
Out[50]:“c”

pandas中的许多聚合函数(如max)不支持对非数字类型(如
string
object
)的操作。您可以尝试将数据转换为数字类型(这也将提高大型数据集的性能)

您可以使用
temp.astype
转换序列

[47]中的
:s
出[47]:
a 1
b 2
C3
名称:0,数据类型:对象
In[48]:s.astype(float)
出[48]:
a 1
b 2
C3
名称:0,数据类型:float64
在[50]中:s.astype(float.idxmax()
Out[50]:“c”

先转换为数字。首先将对象数据类型columnCast转换为数值。您有一个对象数据类型列