数据是之前爬取到的。这里使用jupyter notebook,开始先导入库:
import matplotlib
from matplotlib import pyplot as plt
import pandas as pd
import re
数据读取:
# read file
df = pd.read_csv("data.csv", encoding="gbk")
# delete empty rows
df.dropna(axis=0, how="all", inplace=True)
df
获取需要的数据:
# 根据工作年限分类,然年计数
work_year = df.groupby(by="workYear").count()
# 取出需要的数据
datas = work_year["companyFullName"]
year = []
nums = []
for index, num in datas.items():
year.append(index)
nums.append(num)
print(year)
print(nums)
作图:
#指定默认字体,可以支持中文
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['font.family']='sans-serif'
explode = [0, 0, 0, 0, 0, 0]
plt.figure(dpi=100)
plt.pie(
x=nums,
labels=year,
explode=explode, # 突出显示哪一部分内容
autopct='%.1f%%', # 设置百分比的格式
radius=1, # 半径
)
plt.title("工作年限要求比例:")
结果如下