首页 > 其他 > 详细

关于中国大学排名的数据分析

时间:2020-05-17 16:47:13      阅读:99      评论:0      收藏:0      [点我收藏+]

首先找到一个靠谱的排名网站,并利用F12或者右键查询元素找到我们所需数据的存储位置:

技术分享图片

在利用pip下载所需的第三方库如:matplotlib等进行编写代码:

import requests
import bs4
from bs4 import BeautifulSoup
import matplotlib.pyplot as plt
url = ‘http://m.gaosan.com/gaokao/265440.html‘
r=requests.get(url)
try:
r.raise_for_status()
r.encoding=r.apparent_encoding
data=r.text
except:
print(‘ERROR‘)
soup=BeautifulSoup(data,‘html.parser‘)
b=[]
for tr in soup.find(‘tbody‘).children:
if isinstance(tr,bs4.element.Tag):
tds=tr(‘td‘)
b.append([tds[1].string,tds[2].string])
x=[]
y=[]
for i in range(1,20):
x.append(b[i][0])
y.append(b[i][1])

x.reverse()
y.reverse()
plt.barh(range(len(y)),y,tick_label=x,color=‘red‘)
plt.rcParams[‘font.sans-serif‘] = [‘STKaiTi‘]
plt.rcParams[‘axes.unicode_minus‘] = False
plt.title("中国大学排名及综合得分")
plt.show()

效果如图:技术分享图片

 

关于中国大学排名的数据分析

原文:https://www.cnblogs.com/wzler-13/p/12905708.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!