我无法将列“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'
使用
pd.to_numeric
将字符串值转换为允许比较的数值:相关问题 更多 >
编程相关推荐