导入包

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

读文件

df=pd.read_csv(r'C:\Users\MSI\Desktop\1.csv')

查看数据

df.head()

查看基本信息

df.info()

一共有九个字段,22739条数据,数据全为字符串,不存在数据为空的情况,因此不需要进行对缺少数据的处理

对重复数据进行处理,删除职位和公司重复值

df.drop_duplicates(['PositionName','CompanyName'],keep='first', inplace=True)

查看处理后的信息

df.info()



剩余21851条记录

查看薪资的分布的频率,发现面议有较大的比重

df['Salary'].str[0:].value_counts(normalize = True)



自定义函数drops,删除薪资中的面议

def drops(col, tag):
df.drop(df[df[col].str.contains(tag)].index, inplace=True)
drops('Salary', '面议')



自定义函数cutWord求平均薪资

def cutWord(word,method):
position=word.find("-")
length = len(word)
if position != -1:
bottomSalary = word[:position]
topSalary = word[position + 1:length - 1]
if method == 'bottom':
return bottomSalary
else:
return topSalary df['topSalary']=df.Salary.apply(cutWord,method='top')
df['bottomSalary']=df.Salary.apply(cutWord,method='bottom') df.topSalary=df.topSalary.astype("int")
df.bottomSalary=df.bottomSalary.astype("int") df['avgSalary']=df.apply(lambda x:(x.bottomSalary+x.topSalary)/2,axis=1)
df['avgSalary'].value_counts



由于各个仅统计各个省份,但所给数据中含有地级市及区等,因此对数据进行处理,仅保留省份/直辖市

自定义函数newCity

def newCity(city):
if(len(str(city))>2):
newcity = city[:2]
else:
newcity=city
return newcity df['newcity']=df.City.apply(newCity)

数据基本处理完成,保存为df_clean

df_clean = df[["PositionName", "CompanyName", "newcity", "Experience", "JobWords", "avgSalary"]]
df_clean.head()



查看数据的描述性信息

print(df_clean.describe())



平均薪资:21.85W,中位数:19W,最高:177.5W

薪资分布情况图

plt.rcParams['font.sans-serif']=['SimHei']
df_clean.avgSalary.hist(bins=20)
plt.show()



分割experience,不知道为什么这里分割了八个出来,我就定义了8列。不太懂我觉的这里应该四列才对,8列弄出来之后再把多的删了

info_split=df_clean['Experience'].str.split(' ',expand=True)
info_split.columns=['education','experience','language','age','1','2','3','4'] newExp=info_split.drop(['1','2','3','4'],axis=1) display(newExp)

display(df_clean)

然后把两个二维表进行链接,再保存为new_df,最开始是链接之后删除experience,但是不知道为什么链接之后删除newcity就变成了city,之前的city白处理了。然后就直接保存了

newDF=pd.concat([df_clean, newExp], axis=1)

new_df = newDF[["PositionName", "CompanyName", "newcity",'education','experience','language','age' , "JobWords", "avgSalary"]]

display(new_df)



转换分类数据,这里发现本科有两个,然后其他数据不是很直观,后续有对这个数据进行了处理

new_df.education.astype('category')



自定义newEdu处理教育水平,写的有点复杂,之前的写法不知道为什么最后的结构只剩下本科和硕士。

def newEdu(education):
if education == "硕士及以上":
new_edu = "硕士"
elif education == "统招本科":
new_edu = "本科"
elif education == "本科及以上":
new_edu = "本科"
elif education== "学历不限":
new_edu = "不限"
elif education== "大专及以上":
new_edu = "大专"
elif education == "中专/中技及以上":
new_edu = "中专"
else:
new_edu="博士"
return new_edu new_df['new_edu'] = new_df.education.apply(newEdu) new_df.new_edu.astype('category')



选用线箱进行比较。其最大的优点就是不受异常值的影响,可以以一种相对稳定的方式描述数据的平均水平、波动程度和异常值分布情况。

new_df.new_edu=new_df.new_edu.astype('category')
new_df.new_edu.cat.set_categories(["中专", "博士", "大专", "不限", "本科", "硕士", ],inplace=True)
ax=new_df.boxplot(column='avgSalary',by='new_edu',figsize=(9,6))

print(new_df.groupby(new_df.new_edu).avgSalary.mean().sort_values(ascending=False))



如图1,本科中位数薪资高于硕士生,容易误以为本科薪资高于硕士生,但同时结合图2,可见硕士生的平均薪资水平远高于本科生,由此可知,学历越高,薪资越高,知识改变命运。

转化数据类型(工作年限)创建线箱进行比较

new_df.experience.astype('category')

new_df.boxplot(column='avgSalary',by='experience',figsize=(9,6))



工作年限和薪资的比较

print(new_df.groupby(new_df.experience).avgSalary.mean().sort_values(ascending=False))



薪资与工作年限有很大关系,但优秀员工薪资明显超越年限限制。

北京和上海这两座城市,学历对薪资的影响

df_sz_bj=new_df[new_df['newcity'].isin(['上海','北京'])]
df_sz_bj.boxplot(column='avgSalary',by=['new_edu','newcity'],figsize=[14,6])
plt.show()



薪资与工作区域有很大关系,北京薪资不管什么学历都高于同等学历的薪资状况

不同城市,招聘数据分析需求前五的公司

自定义了函数topN,将传入的数据计数,并且从大到小返回前五的数据。然后以newcity聚合分组,因为求的是前5的公司,所以对CompanyName调用topN函数。

new_df.groupby('CompanyName').avgSalary.agg(lambda x:max(x)-min(x))

def topN(df,n=5):
counts=df.value_counts()
return counts.sort_values(ascending=False)[:n] print(new_df.groupby('newcity').CompanyName.apply(topN))

职位需求的前五,以计算机行业为主

print(new_df.groupby('newcity').PositionName.apply(topN))



将上海和北京的薪资数据以直方图的形式进行对比

plt.hist(x=new_df[new_df.newcity=='上海'].avgSalary,
bins=15,
density=1,
facecolor='blue',
alpha=0.5)
plt.hist(x=new_df[new_df.newcity=='北京'].avgSalary,
bins=15,
density=1,
facecolor='red',
alpha=0.5)
plt.show()



做一个所需要做的工作的词云,先下载wordcloud库

在anaconda下载第三方库还挺麻烦的,镜像还不能用,只能下载之后导包

查看数据进行处理

print(new_df.JobWords)



重置索引然后作词云

df_word_counts=df_word.unstack().dropna().reset_index().groupby('level_0').count()

from wordcloud import WordCloud
df_word_counts.index=df_word_counts.index.str.replace("'","") wc=WordCloud(font_path=r'C:\Windows\Fonts\FZSTK.TTF',width=900,height=400,background_color='white')
fig,ax=plt.subplots(figsize=(20,15))
wc.fit_words(df_word_counts.level_1)
ax=plt.imshow(wc)
plt.axis('off')
plt.show()



上图可见对统计分析,数学,英语和office使用还是有一定的要求。

完整代码
#!/usr/bin/env python
# coding: utf-8 import pandas as pd
import numpy as np
import matplotlib.pyplot as plt df=pd.read_csv(r'C:\Users\MSI\Desktop\1.csv') df.head() df.info() df.drop_duplicates(['PositionName','CompanyName'],keep='first', inplace=True) df.info() df['Salary'].str[0:].value_counts(normalize = True) def drops(col, tag):
df.drop(df[df[col].str.contains(tag)].index, inplace=True) drops('Salary', '面议') df['Salary'].str[0:].value_counts(normalize = True) def cutWord(word,method):
position=word.find("-")
length = len(word)
if position != -1:
bottomSalary = word[:position]
topSalary = word[position + 1:length - 1]
if method == 'bottom':
return bottomSalary
else:
return topSalary df['topSalary']=df.Salary.apply(cutWord,method='top')
df['bottomSalary']=df.Salary.apply(cutWord,method='bottom') df.topSalary=df.topSalary.astype("int")
df.bottomSalary=df.bottomSalary.astype("int") df['avgSalary']=df.apply(lambda x:(x.bottomSalary+x.topSalary)/2,axis=1) df['avgSalary'].value_counts def newCity(city):
if(len(str(city))>2):
newcity = city[:2]
else:
newcity=city
return newcity df['newcity']=df.City.apply(newCity) df_clean = df[["PositionName", "CompanyName", "newcity", "Experience", "JobWords", "avgSalary"]]
df_clean.head() print(df_clean.describe()) plt.rcParams['font.sans-serif']=['SimHei']
df_clean.avgSalary.hist(bins=20)
plt.show() info_split=df_clean['Experience'].str.split(' ',expand=True)
info_split.columns=['education','experience','language','age','1','2','3','4'] newExp=info_split.drop(['1','2','3','4'],axis=1) display(newExp) display(df_clean) newDF=pd.concat([df_clean, newExp], axis=1) new_df = newDF[["PositionName", "CompanyName", "newcity",'education','experience','language','age' , "JobWords", "avgSalary"]] display(new_df) new_df.education.astype('category') def newEdu(education):
if education == "硕士及以上":
new_edu = "硕士"
elif education == "统招本科":
new_edu = "本科"
elif education == "本科及以上":
new_edu = "本科"
elif education== "学历不限":
new_edu = "不限"
elif education== "大专及以上":
new_edu = "大专"
elif education == "中专/中技及以上":
new_edu = "中专"
else:
new_edu="博士"
return new_edu new_df['new_edu'] = new_df.education.apply(newEdu) new_df.new_edu.astype('category') new_df.new_edu=new_df.new_edu.astype('category')
new_df.new_edu.cat.set_categories(["中专", "博士", "大专", "不限", "本科", "硕士", ],inplace=True)
ax=new_df.boxplot(column='avgSalary',by='new_edu',figsize=(9,6)) print(new_df.groupby(new_df.new_edu).avgSalary.mean().sort_values(ascending=False)) new_df.experience.astype('category') new_df.boxplot(column='avgSalary',by='experience',figsize=(9,6)) print(new_df.groupby(new_df.experience).avgSalary.mean().sort_values(ascending=False)) df_sz_bj=new_df[new_df['newcity'].isin(['上海','北京'])]
df_sz_bj.boxplot(column='avgSalary',by=['new_edu','newcity'],figsize=[14,6])
plt.show() new_df.groupby('CompanyName').avgSalary.agg(lambda x:max(x)-min(x)) def topN(df,n=5):
counts=df.value_counts()
return counts.sort_values(ascending=False)[:n] print(new_df.groupby('newcity').CompanyName.apply(topN)) print(new_df.groupby('newcity').PositionName.apply(topN)) plt.hist(x=new_df[new_df.newcity=='上海'].avgSalary,
bins=15,
density=1,
facecolor='blue',
alpha=0.5)
plt.hist(x=new_df[new_df.newcity=='北京'].avgSalary,
bins=15,
density=1,
facecolor='red',
alpha=0.5)
plt.show() print(new_df.JobWords) df_word_counts=df_word.unstack().dropna().reset_index().groupby('level_0').count() from wordcloud import WordCloud
df_word_counts.index=df_word_counts.index.str.replace("'","") wc=WordCloud(font_path=r'C:\Windows\Fonts\FZSTK.TTF',width=900,height=400,background_color='white')
fig,ax=plt.subplots(figsize=(20,15))
wc.fit_words(df_word_counts.level_1)
ax=plt.imshow(wc)
plt.axis('off')
plt.show()

参考资料:

https://www.jianshu.com/p/1e1081ca13b5

python 招聘数据分析的更多相关文章

  1. 利用Python进行数据分析(12) pandas基础: 数据合并

    pandas 提供了三种主要方法可以对数据进行合并: pandas.merge()方法:数据库风格的合并: pandas.concat()方法:轴向连接,即沿着一条轴将多个对象堆叠到一起: 实例方法c ...

  2. 利用Python进行数据分析(5) NumPy基础: ndarray索引和切片

    概念理解 索引即通过一个无符号整数值获取数组里的值. 切片即对数组里某个片段的描述. 一维数组 一维数组的索引 一维数组的索引和Python列表的功能类似: 一维数组的切片 一维数组的切片语法格式为a ...

  3. 利用Python进行数据分析(9) pandas基础: 汇总统计和计算

    pandas 对象拥有一些常用的数学和统计方法.   例如,sum() 方法,进行列小计:   sum() 方法传入 axis=1 指定为横向汇总,即行小计:   idxmax() 获取最大值对应的索 ...

  4. 利用Python进行数据分析(8) pandas基础: Series和DataFrame的基本操作

    一.reindex() 方法:重新索引 针对 Series   重新索引指的是根据index参数重新进行排序. 如果传入的索引值在数据里不存在,则不会报错,而是添加缺失值的新行. 不想用缺失值,可以用 ...

  5. 利用Python进行数据分析(7) pandas基础: Series和DataFrame的简单介绍

    一.pandas 是什么 pandas 是基于 NumPy 的一个 Python 数据分析包,主要目的是为了数据分析.它提供了大量高级的数据结构和对数据处理的方法. pandas 有两个主要的数据结构 ...

  6. 利用Python进行数据分析(4) NumPy基础: ndarray简单介绍

    一.NumPy 是什么 NumPy 是 Python 科学计算的基础包,它专为进行严格的数字处理而产生.在之前的随笔里已有更加详细的介绍,这里不再赘述. 利用 Python 进行数据分析(一)简单介绍 ...

  7. 《利用python进行数据分析》读书笔记 --第一、二章 准备与例子

    http://www.cnblogs.com/batteryhp/p/4868348.html 第一章 准备工作 今天开始码这本书--<利用python进行数据分析>.R和python都得 ...

  8. 利用python进行数据分析之绘图和可视化

    matplotlib API入门 使用matplotlib的办法最常用的方式是pylab的ipython,pylab模式还会向ipython引入一大堆模块和函数提供一种更接近与matlab的界面,ma ...

  9. 利用Python进行数据分析——Numpy基础:数组和矢量计算

    利用Python进行数据分析--Numpy基础:数组和矢量计算 ndarry,一个具有矢量运算和复杂广播能力快速节省空间的多维数组 对整组数据进行快速运算的标准数学函数,无需for-loop 用于读写 ...

随机推荐

  1. 讲两个int 数组找出重复的数字 用最少的循环

    int a[] = {1,3}; int b[] = {1,3,5}; int size = a.length>b.length ?a.length:b.length; int valueA = ...

  2. 记 CentOS 服务器上安装 neo4j 图数据库及本地访问

    下载 去官网下载压缩包放到服务器上.地址为neo4j 下载中心,我这里选择的是 Neo4j 3.5.25 (tar).具体如何做呢?我这里使用的是土方法,即先压缩包下载到本地电脑(win 10系统), ...

  3. 152. Maximum Product Subarray动态规划连乘最大子串

    Find the contiguous subarray within an array (containing at least one number)which has the largest p ...

  4. 【STL 源码剖析】浅谈 STL 迭代器与 traits 编程技法

    大家好,我是小贺. 点赞再看,养成习惯 文章每周持续更新,可以微信搜索「herongwei」第一时间阅读和催更,本文 GitHub : https://github.com/rongweihe/Mor ...

  5. 笔记本使用网线连接可以进行ftp下载,但是通过wifi连接只能登陆不能下载的问题。

    环境: (1)服务器为阿里云服务器,有公网ip,有内网ip,公网和内网已经做了相关端口的映射,ftp服务器为FileZilla,ftp服务器被动模式已开启,防火墙已关闭 (2)ftp客户端为java写 ...

  6. Spring Security OAuth2.0认证授权三:使用JWT令牌

    Spring Security OAuth2.0系列文章: Spring Security OAuth2.0认证授权一:框架搭建和认证测试 Spring Security OAuth2.0认证授权二: ...

  7. 500 份源码合集——GitHub 热点速览 v.21.02

    作者:HelloGitHub-小鱼干 GitHub 项目名,如同变量命名,一个好的项目名能让你一眼就知道它是什么.500-AI-Machine-learning-Deep-learning-Compu ...

  8. maven 无法导入ojdbc 的jar包 解决方法

    由于maven无法在线安装ojdbc包,所有先在我们需要手动导入. 准备环境: 1.系统需要配置好jdk以及maven环境. 2.ojdbc的jar包,记住jar的路径,我的路径是:E:\jdbc\o ...

  9. 【C++】《Effective C++》第九章

    杂项讨论 条款53:不要轻忽编译器的警告 请记住 严肃对待编译器发出的警告信息.努力在你的编译器的最高(最严苛)警告级别下争取"无任何警告"的容易. 不要过度依赖编译器的报警能力, ...

  10. Linux Bash Shell常用快捷键

    Linux Bash Shell常用快捷键 table { margin: auto } 快捷键 功能 tab 补全 ctrl + a 光标回到命令行首 ctrl + e 光标回到命令行尾 ctrl ...