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
Post a Comment