如何在类透视表中显示多个列的最频繁值?你知道吗
我想让这个表模仿这个report中第43页的表。 换句话说:我想得到一张前10名雇主的表格,如下表所示:
雇主;认证职位;认证职位的百分比;该雇主的最高工作状态;该雇主的最高职业。
德勤;163000;14%;宾夕法尼亚;计算机系统分析师
水价;54000;5%;加州;会计师
(很抱歉,降价表的格式不正确)。你知道吗
这是一种split/apply/combine类型的操作。你知道吗
我尝试使用以下代码执行上述操作:
# select the cols in the table
cols = ['employer_name', 'case_status', 'worksite_state', 'soc_name']
# decide which aggregation function each col shoudl have in the table
agg_dict = {'employer_name':'count', 'case_status':'most_frequent',
'worksite_state':'most_frequent', 'soc_name':'most_frequent'}
# select rows the case_status is certified
rows = df.case_status == CERTIFIED
# print out the table
df[rows].groupby('employer_name')[cols].agg(agg_dict).sort_values(by='employer_name').head(10)
下面是数据集的第一行。你知道吗
index 352027
case_number I-200-14111-816263
case_status CERTIFIED
case_submitted 2014-04-21 16:49:19
decision_date 2014-04-25 22:00:47
employer_city PHILADELPHIA
employer_name DELOITTE CONSULTING LLP
employer_postal_code 19103
employment_end_date 2017-04-22 00:00:00
employment_start_date 2014-04-22 00:00:00
full_time_position Y
job_title SENIOR CONSULTANT
naic_code 54161
prevailing_wage 110094
pw_source_other OFLC ONLINE DATA CENTER
pw_source_year 2013
pw_unit_of_pay Year
pw_wage_source OES
soc_code 15-1133
soc_name Software Developers, Systems Software
total_workers 1
visa_class H-1B
wage_rate_of_pay_from 115800
wage_rate_of_pay_to NaN
wage_unit_of_pay Year
worksite_city SAN JOSE
worksite_state California
目前没有回答
相关问题 更多 >
编程相关推荐