赞
踩
首先十分感谢在博主(Radish_c-CSDN博客)的帮助下,完成了这个实验的1-3关,然后第4-5关就卡住了,然后搜了好久,这个实验4和5平台上只有博主 (Radish_c-CSDN博客)这个需要更改命令行的答案,博主的原文章在这里
Python应用-Scrapy爬虫之拉勾网招聘数据分析-CSDN博客
Python应用-Scrapy爬虫之拉勾网招聘数据分析(4,5关)_最低薪资柱状图csdn-CSDN博客
so,更新了一个可以直接通过的第4关、第5关的代码
第4关
-
- #********** Begin **********#
- #1.导入基础包
- import numpy as np
- import pandas as pd
- import matplotlib
- # Force matplotlib to not use any Xwindows backend.
- matplotlib.use('Agg')
- import matplotlib.pyplot as plt
- import re
-
- #2.导入文档数据
- path = r'step4/'
- filePath = path+r'positions.csv'
- df = pd.read_csv(filePath,encoding='gbk')
- #3.分析数据
- b1 = pd.DataFrame(df['salarylow'].value_counts())
- b1.sort_index(inplace=True)
- X = b1.index.tolist()
- Y = list(b1.salarylow)
- #4.画图
- x = np.arange(len(X))+1
- width = 0.5
- fig,ax = plt.subplots()
- ax.bar(x,Y,width)
- for p in ax.patches:
- ax.annotate(str(p.get_height()), xy=(p.get_x(), p.get_height()))
- #********** End **********#
- plt.savefig(path+r'/yourimg/'+r'bar.png') #存储图片
第5关
- #********** Begin **********#
- #1.导入基础包
- import numpy as np
- import pandas as pd
- import matplotlib
- #强制matplotlib不使用任何Xwindows后端(X Window图形用户接口)
- matplotlib.use('Agg')
- import matplotlib.pyplot as plt
- import re
- # 防止中文乱码
- matplotlib.rcParams['font.sans-serif'] = ['SimHei']
- matplotlib.rcParams['font.family']='sans-serif'
-
- #2.导入文档数据
- path = r'step5/'
- filePath = path + r'positions.csv'
- df = pd.read_csv(filePath,encoding = 'gbk')
- #3.分析数据
- c = pd.DataFrame(df['salarylow'].value_counts())
- c.sort_index(inplace=True)
- X1 = c.index.tolist()
- Y1 = list(c.salarylow)
-
- d = pd.DataFrame(df['salaryhigh'].value_counts())
- d.sort_index(inplace=True)
- X2 = d.index.tolist()
- Y2 = list(d.salaryhigh)
- x1 = np.arange(len(X1))+1
- x2 = np.arange(len(X2))+1
- #4.画图
- plt.title('薪资走势图') #给图设置标题
- plt.plot(x1, Y1, color='g', label='salarylow')
- plt.plot(x2, Y2, color='red', label='salaryhigh')
- plt.legend() # 显示图例
- plt.xlabel('薪资')
- plt.ylabel('职位数')
- #********** End **********#
- plt.savefig(path+r'/yourimg/'+r'plot.png') #存储图片
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。