【问题标题】:Finding country with highest percentage of workers working above 50K寻找工作在 50K 以上的工人比例最高的国家
【发布时间】:2020-07-22 12:01:34
【问题描述】:

需要计算哪个国家/地区的收入超过 5 万的人口比例最高? 这是使用的数据集的预览 预期答案是伊朗,占 41.9% 1994 census dataset 我的方法

country = df[df['income']==">50K"][['sex','native.country']] top = country.describe()                                                         top.loc['top','native.country']

【问题讨论】:

  • 你尝试了什么?
  • 问题是我是数据分析新手,这是我试图解决的练习题之一,因此我将其发布在这里以寻求社区帮助。
  • 到目前为止我的代码@Priyal country = df[df['income']==">50K"][['sex','native.country']] top = country.describe() top.loc['top','native.country']
  • 那么,既然您不能再编辑评论了 - 接受我的建议,删除该评论并将信息移动到问题中怎么样?请。

标签: python jupyter-notebook data-science data-analysis


【解决方案1】:

假设您将数据集存储到名为 new 的变量中。

#converting your sex column into numerical values to calculate the population
gender={'male':1,'female':2}
new.sex=[gender[item] for item in new.sex]

#calculating your desired result

data=new.loc[new.income>50K,['sex','native.country']]
result=data.groupby('native.country')['sex'].sum()
print(result)

这将为您提供收入超过 5 万的人口最多的国家/地区的名称。

然后,如果您仍然想找到人口百分比,您可以使用以下方法轻松完成:

total=data['sex'].sum()
list1=[]
for i in result:
    list1.append(i/total*100)
print(list1)

希望你能从我的回答中得到一些帮助。

快乐编码:)

【讨论】:

  • 我的方法country = df[df['income']==">50K"][['sex','native.country']] top = country.describe() top.loc['top','native.country']
  • 感谢您的帮助。
  • 非常感谢!!!是的,你的方法很好。
猜你喜欢
  • 1970-01-01
  • 2016-11-15
  • 2022-06-16
  • 2019-04-28
  • 1970-01-01
  • 2022-01-20
  • 2020-11-11
  • 2017-02-12
  • 1970-01-01
相关资源
最近更新 更多