|
| 1 | +import numpy as np |
| 2 | +from pyecharts import options as opts |
| 3 | +from pyecharts.charts import Bar |
| 4 | +from pyecharts.charts import Pie |
| 5 | +from wordcloud import WordCloud |
| 6 | +import matplotlib.pyplot as plt |
| 7 | +import json |
| 8 | +import pandas as pd |
| 9 | + |
| 10 | + |
| 11 | +def get_data(): |
| 12 | + with open('data.txt') as f: |
| 13 | + data = [] |
| 14 | + for line in f.readlines(): |
| 15 | + result = json.loads(line) |
| 16 | + result_list = result['content']['positionResult']['result'] |
| 17 | + for item in result_list: |
| 18 | + dict = { |
| 19 | + 'city': item['city'], |
| 20 | + 'industryField': item['industryField'], |
| 21 | + 'education': item['education'], |
| 22 | + 'workYear': item['workYear'], |
| 23 | + 'salary': item['salary'], |
| 24 | + 'firstType': item['firstType'], |
| 25 | + 'secondType': item['secondType'], |
| 26 | + 'thirdType': item['thirdType'], |
| 27 | + # list |
| 28 | + 'skillLables': ','.join(item['skillLables']), |
| 29 | + 'companyLabelList': ','.join(item['companyLabelList']) |
| 30 | + } |
| 31 | + data.append(dict) |
| 32 | + return data |
| 33 | + |
| 34 | + |
| 35 | +data = get_data() |
| 36 | +data = pd.DataFrame(data) |
| 37 | +data.head(5) |
| 38 | + |
| 39 | +# 城市图 |
| 40 | +citys_value_counts = data['city'].value_counts() |
| 41 | +top = 15 |
| 42 | +citys = list(citys_value_counts.head(top).index) |
| 43 | +city_counts = list(citys_value_counts.head(top)) |
| 44 | + |
| 45 | +bar = ( |
| 46 | + Bar() |
| 47 | + .add_xaxis(citys) |
| 48 | + .add_yaxis("", city_counts) |
| 49 | +) |
| 50 | +bar.render_notebook() |
| 51 | + |
| 52 | +# 城市图 |
| 53 | +pie = ( |
| 54 | + Pie() |
| 55 | + .add("", [list(z) for z in zip(citys, city_counts)]) |
| 56 | + .set_global_opts(title_opts=opts.TitleOpts(title="")) |
| 57 | + .set_global_opts(legend_opts=opts.LegendOpts(is_show=False)) |
| 58 | +) |
| 59 | +pie.render_notebook() |
| 60 | + |
| 61 | +# 行业 |
| 62 | +industrys = list(data['industryField']) |
| 63 | +industry_list = [i for item in industrys for i in item.split(',')] |
| 64 | + |
| 65 | +industry_series = pd.Series(data=industry_list) |
| 66 | +industry_value_counts = industry_series.value_counts() |
| 67 | + |
| 68 | +industrys = list(industry_value_counts.head(top).index) |
| 69 | +industry_counts = list(industry_value_counts.head(top)) |
| 70 | + |
| 71 | +pie = ( |
| 72 | + Pie() |
| 73 | + .add("", [list(z) for z in zip(industrys, industry_counts)]) |
| 74 | + .set_global_opts(title_opts=opts.TitleOpts(title="")) |
| 75 | + .set_global_opts(legend_opts=opts.LegendOpts(is_show=False)) |
| 76 | +) |
| 77 | +pie.render_notebook() |
| 78 | + |
| 79 | +# 学历 |
| 80 | +eduction_value_counts = data['education'].value_counts() |
| 81 | + |
| 82 | +eduction = list(eduction_value_counts.index) |
| 83 | +eduction_counts = list(eduction_value_counts) |
| 84 | + |
| 85 | +pie = ( |
| 86 | + Pie() |
| 87 | + .add("", [list(z) for z in zip(eduction, eduction_counts)]) |
| 88 | + .set_global_opts(title_opts=opts.TitleOpts(title="")) |
| 89 | + .set_global_opts(legend_opts=opts.LegendOpts(is_show=False)) |
| 90 | +) |
| 91 | +pie.render_notebook() |
| 92 | + |
| 93 | +# 工作年限 |
| 94 | +work_year_value_counts = data['workYear'].value_counts() |
| 95 | +work_year = list(work_year_value_counts.index) |
| 96 | +work_year_counts = list(work_year_value_counts) |
| 97 | + |
| 98 | +bar = ( |
| 99 | + Bar() |
| 100 | + .add_xaxis(work_year) |
| 101 | + .add_yaxis("", work_year_counts) |
| 102 | +) |
| 103 | +bar.render_notebook() |
| 104 | + |
| 105 | +# 技能 |
| 106 | +word_data = data['skillLables'].str.split(',').apply(pd.Series) |
| 107 | +word_data = word_data.replace(np.nan, '') |
| 108 | +text = word_data.to_string(header=False, index=False) |
| 109 | + |
| 110 | +wc = WordCloud(font_path='/System/Library/Fonts/PingFang.ttc', background_color="white", scale=2.5, |
| 111 | + contour_color="lightblue", ).generate(text) |
| 112 | + |
| 113 | +plt.figure(figsize=(16, 9)) |
| 114 | +plt.imshow(wc) |
| 115 | +plt.axis('off') |
| 116 | +plt.show() |
| 117 | + |
| 118 | +# 福利 |
| 119 | +word_data = data['companyLabelList'].str.split(',').apply(pd.Series) |
| 120 | +word_data = word_data.replace(np.nan, '') |
| 121 | +text = word_data.to_string(header=False, index=False) |
| 122 | + |
| 123 | +wc = WordCloud(font_path='/System/Library/Fonts/PingFang.ttc', background_color="white", scale=2.5, |
| 124 | + contour_color="lightblue", ).generate(text) |
| 125 | + |
| 126 | +plt.figure(figsize=(16, 9)) |
| 127 | +plt.imshow(wc) |
| 128 | +plt.axis('off') |
| 129 | +plt.show() |
| 130 | + |
| 131 | +# 薪资 |
| 132 | +salary_value_counts = data['salary'].value_counts() |
| 133 | +salary = list(salary_value_counts.head(top).index) |
| 134 | +salary_counts = list(salary_value_counts.head(top)) |
| 135 | + |
| 136 | +bar = ( |
| 137 | + Bar() |
| 138 | + .add_xaxis(salary) |
| 139 | + .add_yaxis("", salary_counts) |
| 140 | + .set_global_opts(xaxis_opts=opts.AxisOpts(name_rotate=0, name="薪资", axislabel_opts={"rotate": 45})) |
| 141 | +) |
| 142 | +bar.render_notebook() |
0 commit comments