前言
嗨喽~大家好呀,这里是魔王呐 ❤ ~

今天案例难度指数: ☆☆☆
准备
环境使用:
-
Anaconda (python3.9)
-->识别我们写的代码
开发工具:
-
jupyter notebook
-->代码编辑功能敲代码的工具
相关模块:
- seaborn pandas matplotlib
数据

步骤
-
读取数据
-
数据预处理
-
可视化
代码展示
1. 导入模块
import pandas as pd
import matplotlib.pyplot as plt # 最基础的可视化
import seaborn as sns # 以plt为基础封装
sns.set_style('white',{'font.sans-serif':['simhei','Arial']})
2. 读取数据
df = pd.read_csv('lagouw.csv')
3. 预览数据
df.head()

数据预处理
-
转化统一的大小写
-
提取数字 正则提取 extract()
-
转化为int类型 映射
-
取区间的平均值
df['工资'] = df['工资'].str.lower()\
.str.extract(r'(\d+)[k]-(\d+)[k]')\
.applymap(lambda x:int(x))\
.mean(axis=1)
df['工资']

city_order = df.groupby('工作城市')['工资'].mean()
city_order.sort_values() # 排序

city_order.index.tolist()

city_order = df.groupby('工作城市')['工资'].mean()\
.sort_values()\
.index.tolist()
city_order
可视化
fig,ax = plt.subplots(figsize=(12,8))
sns.barplot(x='工作城市',y='工资',order=city_order,data=df,palette='RdBu_r')
fig.text(x=0.04,y=0.9,s=' 各个城市的薪资水平对比 ',fontsize=32,weight='bold',color='w',
backgroundcolor='#3c7f99')
# 去掉边框
plt.box(False)
ax.yaxis.grid(which='both', linewidth=0.5, color='#3c7f99') # ax.xaxis.grid()打开x轴的网格线

fig, ax = plt.subplots(figsize=(12,8))
sns.countplot(y="工作城市",order= df["工作城市"].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') # ax.xaxis.grid()打开x轴的网格线
plt.xlabel('')
plt.ylabel('')

推荐往期文章
对python感兴趣的小伙伴也可以看一下博主其他相关文章哦~
python小介绍:
python是什么?工作前景如何?怎么算有基础?爬数据违法嘛?。。
python数据分析前景:
用python分析“数据分析”到底值不值得学习,以及学完之后大概能拿到多少工资
python基础自测题:
最后推荐一套Python视频给大家,希望对大家有所帮助:
尾语
要成功,先发疯,下定决心往前冲!
学习是需要长期坚持的,一步一个脚印地走向未来!
未来的你一定会感谢今天学习的你。
—— 心灵鸡汤
本文章到这里就结束啦~感兴趣的小伙伴可以复制代码去试试哦 😝
网友评论