python - Numpy "where" with multiple conditions -


i try add new column "energy_class" dataframe "df_energy" contains string "high" if "consumption_energy" value > 400, "medium" if "consumption_energy" value between 200 , 400, , "low" if "consumption_energy" value under 200. try use np.where numpy, see numpy.where(condition[, x, y]) treat 2 condition not 3 in case.

any idea me please?

thank in advance

you can use ternary:

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

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -