返回一条消息,并在比较数据集中的值后放入一个新列(使用panda)



我需要查看列Deathrate中的值是否低于9并返回balanced。如果不是,则返回Urgent,并将所有这些放在新列Humanitarian Help中。我首先尝试了这个:

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

试试这个:

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

注意,我将CCD_ 5(大于(改变为CCD_;CCD_ 7比9〃低;

最新更新