文章目录
需求代码实现需求
使用折线图展示“大数据”相关职位招聘数量差异
提取相关信息 ---- “大数据”分组聚合
代码实现
Python、Flask
import pandas as pdfrom flask import Flask,render_template# 读取数据集data = pd.read_csv("G:\Projects\pycharmeProject-C\Flask\dataset\zl0507.csv")# 检查空值print(data.isnull().sum())# 去重print(data.shape)print(data.loc[data.duplicated()])data.drop_duplicates(inplace=True)print(data.shape)# 提取筛选大数据信息dashuju = data['jobName'].str.contains("大数据")print(len(dashuju))data_sel = data.loc[dashuju,['jobName','detail']]print(data_sel.shape[0])# 分组聚合result = data_sel.groupby('jobName').agg(count=('jobName','count')).sort_values('count',ascending=False).reset_index()# 合并数据list = result.values.tolist()# 可视化app = Flask(__name__)@app.route("/")def index():sheets_list = listreturn render_template("zl0507_02.html",sheets = sheets_list)if __name__ == '__main__':app.run(debug=True)
返回顶部
HTML
<!DOCTYPE html><html lang="en" style="height:100%"><head><meta charset="UTF-8"><title>Title</title></head><body style="height:100%"><div id="container" style="height:100%"></div><script type="text/javascript" src="../static/echarts.min.js"></script><script type="text/javascript">var dom = document.getElementById("container");var myecharts = echarts.init(dom);var data = [{% for item in sheets %}'{{item.0}}',{%endfor%}];var data1 = [{% for item in sheets%}{{item.1}},{%endfor%}]var option = null;option = {title:{text:'大数据职业招聘数量差异'},grid:{top:'5%',bottom:'10%',left:'4%',right:'4%',containLabel:true},legend:{show:true},tooltip:{trigger:'axis',axisPointer:{type:'shadow'}},xAxis:{type:'category',data:data,boundaryGap:true,axisTick:{alignWithLabel:true},axisLabel: {interval:0,rotate:90}},yAxis:{type:'value'},series:[{name:'大数据职位',type:'line',data:data1}]};if(option && typeof option=='object'){myecharts.setOption(option);}</script></body></html>
返回顶部
效果展示
返回顶部