类型错误:“str和float实例之间不支持”?

2024-09-27 00:16:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我无法将列“MinTemp”中的值分组为3组并更新数据帧。

“MinTemp”列中的值范围为-8.2至33.9。
我只想有3个组,^{{cd1>}、^{cd2>}(mintp2)和^{{cd3>}(mintp3)。

from collections import Counter

col         = 'MinTemp'

conditions  = [ data_mod[col] > 22.0, (data_mod[col] > 10.0) & (data_mod[col] <= 22.0), data_mod[col] <= 10.0 ]

choices     = [ 'mintp3', 'mintp2', 'mintp1' ]
data_mod["MinTemp"] = np.select(conditions, choices, default='neutral')

Counter(MinTemp)

TypeError: '>' not supported between instances of 'str' and 'float'


Tags: 数据frommoddatacountercolcollectionsconditions

热门问题