You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zxq/就业机会前十的城市.py

42 lines
988 B

import matplotlib.pyplot as plt
import pandas as pd
# 解决中文乱码
plt.rcParams['font.sans-serif'] = ['SimHei']
# 创建画布
plt.figure()
data=pd.read_csv("最新数据.csv")
# 将城市这一列数据提取出来
city = data[["城市",'职位名称']]
# 将城市列去重后转化为列表变成x轴数据
x_data = data['城市'].drop_duplicates().tolist()
x_data=x_data[:10]
# print(x_data)
# 将城市进行分组计数变为y轴数据
y_data = city.groupby('城市').count().reset_index()
y_data = y_data['职位名称'].tolist()
y_data.sort(reverse=True)
y_data=y_data[:10]
plt.bar(x_data, y_data,
width=0.5,
color='#9fe080',
align="center",
)
# 显示数据标签
for a,b in zip(x_data,y_data):
plt.text(
a, #标签的x坐标
b, #标签的y坐标
b, #标签的内容
ha='center',
va='bottom',
fontsize=10)
plt.title("就业机会前十的城市")
plt.xlabel("城市")
plt.show()