脾气暴躁的“哪里”有多个条件

泊松

我尝试将新列“ energy_class”添加到数据框“ df_energy”,如果“ consumption_energy”值> 400,则包含字符串“ high”;如果“ consumption_energy”值在200至400之间,则添加“ medium”,并且“低”(如果“ consumption_energy”值小于200)。我尝试使用numpy中的np.where,但我发现numpy.where(condition[, x, y])仅处理两个条件而不是3。

有什么想法可以帮助我吗?

先感谢您

亚历山大大帝

您可以使用三元

np.where(consumption_energy > 400, 'high', 
         (np.where(consumption_energy < 200, 'low', 'medium')))

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章