首页 > 大数据 > 数据挖掘 > 【爬遍拉钩,带你看看数据分析师的真实现状】
import pandas as pdimport numpy as npimport seaborn as snsfrom pyecharts.charts import Piefrom pyecharts import options as optsimport matplotlib.pyplot as plt%matplotlib inlinesns.set_style('white',{'font.sans-serif':['simhei','Arial']})pd.set_option("display.max_column", None)pd.set_option("display.max_row",None)path = "./data/lagou_11.csv"df = pd.read_csv(path)df.columns# 取出我们进行后续分析所需的字段columns = ["positionName", "companyShortName", "city", "companySize", "education", "financeStage",
"industryField", "salary", "workYear", "hitags", "companyLabelList", "job_detail"]df = df[columns].drop_duplicates() #去重# 原始数据长度len(df)# 数据分析相应的岗位数量cond_1 = df["positionName"].str.contains("数据分析") # 职位名中含有数据分析字眼的cond_2 = ~df["positionName"].str.contains("实习") # 剔除掉带实习字眼的len(df[cond_1 & cond_2]["positionName"])# 筛选出我们想要的字段,并剔除positionNamedf = df[cond_1 & cond_2]df.drop(["positionName"], axis=1, inplace=True)df.reset_index(drop=True, inplace=True)# 处理过程#1、将salary中的字符串均小写化(因为存在8k-16k和8K-16K)#2、运用正则表达式提取出薪资区间#3、将提取出来的数字转化为int型#4、取区间的平均值df["salary"] = df["salary"].str.lower()\ .str.extract(r'(\d+)[k]-(\d+)k')\ .applymap(lambda x:int(x))\ .mean(axis=1)df["job_detail"] = df["job_detail"].str.lower().fillna("") #将字符串小写化,并将缺失值赋值为空字符串df["Python/R"] = df["job_detail"].map(lambda x:1 if ('python' in x) or ('r' in x) else 0)df["SQL"] = df["job_detail"].map(lambda x:1 if ('sql' in x) or ('hive' in x) else 0)df["Tableau"] = df["job_detail"].map(lambda x:1 if 'tableau' in x else 0)df["Excel"] = df["job_detail"].map(lambda x:1 if 'excel' in x else 0)df.head(1)def clean_industry(industry):
industry = industry.split(",")
if industry[0]=="移动互联网" and len(industry)>1:
return industry[1]
else:
return industry[0]df["industryField"] = df.industryField.map(clean_industry)fig, ax = plt.subplots(figsize=(12,8))sns.countplot(y="city",order= df["city"].value_counts().index,data=df,color='#3c7f99')plt.box(False)fig.text(x=0.04, y=0.90, s=' 各城市数据分析岗位的需求量 ',
fontsize=32, weight='bold', color='white', backgroundcolor='#c5b783')plt.tick_params(axis='both', which='major', labelsize=16)ax.xaxis.grid(which='both', linewidth=0.5, color='#3c7f99')plt.xlabel('')plt.ylabel('')industry_index = df["industryField"].value_counts()[:10].indexindustry =df.loc[df["industryField"].isin(industry_index),"industryField"]fig, ax = plt.subplots(figsize=(12,8))sns.countplot(y=industry.values,order = industry_index,color='#3c7f99')plt.box(False)fig.text(x=0, y=0.90, s=' 细分领域数据分析岗位的需求量(取前十) ',
fontsize=32, weight='bold', color='white', backgroundcolor='#c5b783')plt.tick_params(axis='both', which='major', labelsize=16)ax.xaxis.grid(which='both', linewidth=0.5, color='#3c7f99')plt.xlabel('')plt.ylabel('')fig,ax = plt.subplots(figsize=(12,8))city_order = df.groupby("city")["salary"].mean()\ .sort_values()\ .index.tolist()sns.barplot(x="city", y="salary", order=city_order, data=df, ci=95,palette="RdBu_r")fig.text(x=0.04, y=0.90, s=' 各城市的薪资水平对比 ',
fontsize=32, weight='bold', color='white', backgroundcolor='#3c7f99')plt.tick_params(axis="both",labelsize=16,)ax.yaxis.grid(which='both', linewidth=0.5, color='black')ax.set_yticklabels([" ","5k","10k","15k","20k"])plt.box(False)plt.xlabel('')plt.ylabel('')fig,ax = plt.subplots(figsize=(12,8))fig.text(x=0.04, y=0.90, s=' 一线城市的薪资分布对比 ',
fontsize=32, weight='bold', color='white', backgroundcolor='#c5b783')sns.kdeplot(df[df["city"]=='北京']["salary"],shade=True,label="北京")sns.kdeplot(df[df["city"]=='上海']["salary"],shade=True,label="上海")sns.kdeplot(df[df["city"]=='广州']["salary"],shade=True,label="广州")sns.kdeplot(df[df["city"]=='深圳']["salary"],shade=True,label="深圳")plt.tick_params(axis='both', which='major', labelsize=16)plt.box(False)plt.xticks(np.arange(0,61,10), [str(i)+"k" for i in range(0,61,10)])plt.yticks([])plt.legend(fontsize = 'xx-large',fancybox=None)corr = df.pivot_table(index="city",columns="workYear",values="salary")corr = corr[["应届毕业生","1-3年","3-5年","5-10年"]]corr.loc[city_order]fig,ax = plt.subplots(figsize=(10,8))sns.heatmap(corr.loc[df["city"].value_counts().index],cmap="RdBu_r",center=20,annot=True,annot_kws={'fontsize':14})plt.tick_params(axis='x', which='major', labelsize=16)plt.tick_params(axis='y', which='major', labelsize=16,labelrotation=0)plt.xlabel(""),plt.ylabel("")py_rate = df["Python/R"].value_counts(normalize=True).loc[1]sql_rate = df["SQL"].value_counts(normalize=True).loc[1]tableau_rate = df["Tableau"].value_counts(normalize=True).loc[1]excel_rate = df["Excel"].value_counts(normalize=True).loc[1]print("职位技能需求:")print("Python/R:",py_rate)print("SQL:",sql_rate)print("Excel:",excel_rate)print("Tableau:",tableau_rate)def get_level(x):
if x["Python/R"] == 1:
x["skill"] = "Python/R"
elif x["SQL"] == 1:
x["skill"] = "SQL"
elif x["Excel"] == 1:
x["skill"] = "Excel"
else:
x["skill"] = "其他"
return xdf = df.apply(get_level,axis=1)df.head(1)fig,ax = plt.subplots(figsize=(12,8))fig.text(x=0.02, y=0.90, s=' 不同技能的薪资水平对比 ',
fontsize=32, weight='bold', color='white', backgroundcolor='#c5b783')sns.boxplot(y="skill",x="salary",data=df.loc[df.skill!="其他"],palette="husl",order=["Python/R","SQL","Excel"])plt.tick_params(axis="both",labelsize=16)ax.xaxis.grid(which='both', linewidth=0.75)plt.xticks(np.arange(0,61,10), [str(i)+"k" for i in range(0,61,10)])plt.box(False)plt.xlabel('工资', fontsize=18)plt.ylabel('技能', fontsize=18)education = df["education"].value_counts(normalize=True)from pyecharts.commons.utils import JsCodedef new_label_opts():
return opts.LabelOpts(formatter=JsCode("学历要求"))pie = (
Pie()
.add(
"",
[list(z) for z in zip(education.index, np.round(education.values,4))],
center=["50%", "50%"],
radius=["50%","75%"],
label_opts=new_label_opts()
)
.set_global_opts(
title_opts=opts.TitleOpts(title=""),
legend_opts=opts.LegendOpts(
is_show=False
)
)
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {d}%")))pie.render_notebook()company_size_map = {
"2000人以上": 6,
"500-2000人": 5,
"150-500人": 4,
"50-150人": 3,
"15-50人": 2,
"少于15人": 1}workYear_map = {
"10年以上": 6,
"5-10年": 5,
"3-5年": 4,
"1-3年": 3,
"1年以下": 2,
"应届毕业生": 1,}df["company_size"] = df["companySize"].map(company_size)df["work_year"] = df["workYear"].map(workYear_map)df = df.sort_values(by="company_size",ascending=True)df_plot = df.loc[~df.work_year.isna()]color_map = {
5:"#ff0000",
4:"#ffa500",
3:"#c5b783",
2:"#3c7f99",
1:"#0000cd"}df_plot.loc[:,"color"] = df_plot.work_year.map(color_map)def seed_scale_plot():
seeds=np.arange(5)+1
y=np.zeros(len(seeds),dtype=int)
s=seeds*100
colors=['#ff0000', '#ffa500', '#c5b783', '#3c7f99', '#0000cd'][::-1]# colors = sns.color_palette("husl", n_colors=6)
fig,ax=plt.subplots(figsize=(12,1))
plt.scatter(seeds,y,s=s,c=colors,alpha=0.3)
plt.scatter(seeds,y,c=colors)
plt.box(False)
plt.grid(False)
plt.xticks(ticks=seeds,labels=list(workYear_map.keys())[::-1],fontsize=14)
plt.yticks(np.arange(1),labels=[' 经验:'],fontsize=16)fig, ax = plt.subplots(figsize=(12, 8))fig.text(x=0.03, y=0.92, s=' 不同规模公司的用人需求差异 ', fontsize=32,
weight='bold', color='white', backgroundcolor='#3c7f99')plt.scatter(df_plot.salary, df_plot["companySize"], s=df_plot["work_year"]*100 ,alpha=0.35,c=df_plot["color"])plt.scatter(df_plot.salary, df_plot["companySize"], c=df_plot["color"], )plt.tick_params(axis='both', which='both', length=0)plt.tick_params(axis='both', which='major', labelsize=16)ax.xaxis.grid(which='both', linewidth=0.75)plt.xticks(np.arange(0,61,10), [str(i)+"k" for i in range(0,61,10)])plt.xlabel('工资', fontsize=18)plt.box(False)seed_scale_plot()df_skill = df.loc[(df["companySize"]=="2000人以上")&(df.skill!="其他")]["skill"].value_counts(normalize=True)df_skillfig, ax = plt.subplots(figsize=(12, 6))sns.barplot(x=df_skill.index,y=df_skill.values, color='#3c7f99')plt.box(False)fig.text(x=0.08, y=0.9, s=' 大公司对技能的要求占比 ',
fontsize=32, weight='bold', color='white', backgroundcolor='#c5b783')plt.tick_params(axis='both', which='major', labelsize=16)ax.yaxis.grid(which='both', linewidth=0.5, color='#3c7f99')
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69977871/viewspace-2700682/ ,如需转载,请注明出处,否则将追究法律责任。