數據是之前爬取到的。這裏使用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("工作年限要求比例:")
結果如下