我正在与NumPy合作,但面临以下挑战:
这是我的数据:
import numpy as np
# First 20 countries with employment data
countries = np.array([
'Afghanistan', 'Albania', 'Algeria', 'Angola', 'Argentina',
'Armenia', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas',
'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium',
'Belize', 'Benin', 'Bhutan', 'Bolivia',
'Bosnia and Herzegovina'
])
# Employment data in 2007 for those 20 countries
employment = np.array([
55.70000076, 51.40000153, 50.5 , 75.69999695,
58.40000153, 40.09999847, 61.5 , 57.09999847,
60.90000153, 66.59999847, 60.40000153, 68.09999847,
66.90000153, 53.40000153, 48.59999847, 56.79999924,
71.59999847, 58.40000153, 70.40000153, 41.20000076
])
我必须在给定的就业数据中返回就业率最高的国家的名称,以及该国家的就业情况。
这是我的代码:
def max_employment(countries, employment):
max_country = ?????
max_value = employment.max()
return (max_country, max_value)
我被卡住了,返回了就业人数最高的国家的名字
最佳答案
您正在寻找np.argmax
,它将返回最大值的索引:
>>> countries[employment.argmax()]
'Angola'
关于python - 返回Python中就业人数最多的国家/地区的名称,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50115081/