Home > Enterprise >  return a message and put in a new column after compare values in a dataset (using pandas)
return a message and put in a new column after compare values in a dataset (using pandas)

Time:12-17

I need to see if the values in column Deathrate is lower than 9 and return balanced. If isn't return Urgent and put all this in a new column Humanitarian Help. I tried this first:

new = country_data.filter(items=['Country', 'Deathrate']).where(country_data['Deathrate'] > 9)
new = new.dropna()
new

CodePudding user response:

Try this:

import numpy as np

country_data['Humanitarian Help'] = np.where(country_data['Deathrate'] < 9, "balanced", "Deathrate")

Note that I changed > (greater than) to < (less than) per "Deathrate is lower than 9"

  • Related