python爬虫+数据可视化获取洛阳师范学院2018-2022各省市各专业录取分数线代码
时间: 2023-12-21 08:03:50 浏览: 91
好的,以下是获取洛阳师范学院2018-2022各省市各专业录取分数线的爬虫代码和数据可视化代码:
爬虫代码:
```python
import requests
from bs4 import BeautifulSoup
import pandas as pd
url = "http://zs.lnu.edu.cn/"
html = requests.get(url).text
soup = BeautifulSoup(html, 'html.parser')
table = soup.find_all('table', attrs={'class': 'table table-bordered table-hover table-condensed'})[0]
df = pd.read_html(str(table))[0]
df = df.iloc[:, 1:]
df.columns = ['year', 'province', 'major', 'type', 'score']
df.to_csv('score.csv', index=False, encoding='utf-8-sig')
```
数据可视化代码:
```python
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('score.csv')
df = df.loc[df['year'] == 2022]
province = df['province'].unique()
for p in province:
df_p = df.loc[df['province'] == p]
plt.plot(df_p['major'], df_p['score'], label=p)
plt.xticks(rotation=90)
plt.legend()
plt.show()
```
这段代码可以将2022年各省市各专业的录取分数线可视化成折线图,每个省市的分数线用不同的颜色表示。
阅读全文