前言
- 將該高校的地理位置以地圖的形式展示。
- 將該高校近幾年計算機相關(guān)專業(yè)的考研(或高考)錄取成績、人數(shù)信息,專業(yè)師資隊伍,考試科目及內(nèi)容等等以合適的柱狀圖、折線圖、餅圖等方式表示出來,圖表能夠清晰得呈現(xiàn)不同數(shù)據(jù)的變化,使得觀察圖表的人能夠迅速得獲取信息。
- 錄取成績、錄取人數(shù)信息、專業(yè)師資隊伍
- 柱狀圖、折線圖、餅圖
- 對個人感興趣的導(dǎo)師、研究方向等多屬性、多維度、多關(guān)系數(shù)據(jù)選用關(guān)系、詞云等可視化方法,使數(shù)據(jù)清晰有效地表達。
- 研究方向(關(guān)系+詞云)
- 其它自由發(fā)揮部分
一、數(shù)據(jù)介紹
1.1 基本信息
- 學(xué)校名稱:山東理工大學(xué)
- 地理位置:山東省淄博市,北緯36.810315,東經(jīng)117.999601
- 院校:計算機科學(xué)與技術(shù)學(xué)院
1.2 考研信息
- 下載相關(guān)信息:2020考研擬錄取名單:山東理工大學(xué)2020年碩士研究生擬錄取名單
- PDF識別為Excel:PDF在線轉(zhuǎn)換工具、WPS會員(鈔能力)、python
通過網(wǎng)絡(luò)搜集2020-2022年,山東理工大學(xué)計算機科學(xué)與技術(shù)專業(yè)(學(xué)碩+專碩)第一志愿錄取情況信息,具體信息包括:復(fù)試學(xué)院代碼,復(fù)試學(xué)院,姓名,初試考試編號,復(fù)試專業(yè)代碼,復(fù)試專業(yè)名稱,研究方向代碼,學(xué)習(xí)形式,一志愿/調(diào)劑,初試成績,綜合面試成績",總成績,排名,錄取結(jié)果,備注。需要注意的是該數(shù)據(jù)并非來自官網(wǎng)(學(xué)校官網(wǎng)信息已關(guān)閉),在數(shù)據(jù)結(jié)果上存在誤差。
import PyPDF2
import pytesseract
import pandas as pd
import os
# 設(shè)置OCR引擎(如果需要)
# pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract' # 指定Tesseract OCR引擎的路徑
# 將PDF文件轉(zhuǎn)換為文本
def pdf_to_text(pdf_path):
text = ""
with open(pdf_path, 'rb') as file:
reader = PyPDF2.PdfReader(file)
num_pages = len(reader.pages)
for page in range(num_pages):
pdf_page = reader.pages[page]
text += pdf_page.extract_text()
return text
# 使用OCR識別文本
def ocr_text(image_path):
text = pytesseract.image_to_string(image_path)
return text
# 將文本保存為Excel文件
def save_text_as_excel(text, output_path):
lines = text.split('\n')
data = [line.split() for line in lines if line.strip()]
df = pd.DataFrame(data)
df.to_excel(output_path, index=False)
# 主函數(shù)
def pdf_to_excel(pdf_folder, output_folder):
pdf_files = [f for f in os.listdir(pdf_folder) if f.endswith('.pdf')]
for pdf_file in pdf_files:
pdf_path = os.path.join(pdf_folder, pdf_file)
text = pdf_to_text(pdf_path)
# 使用OCR識別文本(如果需要)
# image_path = 'image.png' # 將PDF轉(zhuǎn)換為圖像文件(可選)
# text = ocr_text(image_path)
excel_file = pdf_file.replace('.pdf', '.xlsx')
output_path = os.path.join(output_folder, excel_file)
save_text_as_excel(text, output_path)
print("轉(zhuǎn)換完成!")
# 調(diào)用函數(shù)進行轉(zhuǎn)換
pdf_folder = '/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/'
output_folder = '/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Output/'
pdf_to_excel(pdf_folder, output_folder)
- 其他相關(guān)信息:
- (104)山東理工大學(xué)2020計算機考研數(shù)據(jù)速覽
- (189)山東理工大學(xué)2021計算機考研數(shù)據(jù)速覽,專碩復(fù)試線299分,學(xué)碩接收調(diào)劑
- (112)山東理工大學(xué)22計算機考研數(shù)據(jù)速覽,學(xué)碩接收調(diào)劑
1.3 導(dǎo)師信息
通過山東理工大學(xué)計算機科學(xué)與技術(shù)學(xué)院官網(wǎng),搜集獲取研究生導(dǎo)師信息。
- 獲取信息:姓名、職位、主要學(xué)習(xí)工作簡歷、主要研究方向、社會兼職及榮譽稱號、主講課程及主要教學(xué)獎勵、主要科研成果及獎勵
- 爬取代碼:導(dǎo)師隊伍
import time
import requests
from lxml import etree
import pandas as pd
def scrape_website(url, dataframe):
# 發(fā)起HTTP請求獲取網(wǎng)頁內(nèi)容
response = requests.get(url)
# 檢查請求是否成功
if response.status_code == 200:
# 使用lxml庫解析網(wǎng)頁內(nèi)容
html = response.text
tree = etree.HTML(html)
# 創(chuàng)建字典來存儲爬取的數(shù)據(jù)
data = {}
# 基本信息
item1 = tree.xpath('/html/body/div[4]/div/div[2]/div/div[1]/div[2]/h2//text()')
item2 = tree.xpath('/html/body/div[4]/div/div[2]/div/div[1]/div[2]/h3//text()')
data['Item 1'] = item1
data['Item 2'] = item2
# 主要學(xué)習(xí)工作簡歷
data1 = tree.xpath('/html/body/div[4]/div/div[2]/div/div[2]/div/p//text()')
data['Main Education and Work Experience'] = data1
# 主要研究方向
data2 = tree.xpath('/html/body/div[4]/div/div[2]/div/div[3]/div/p//text()')
data['Main Research Areas'] = data2
# 社會兼職及榮譽稱號
data3 = tree.xpath('/html/body/div[4]/div/div[2]/div/div[4]/div/p//text()')
data['Social Positions and Honors'] = data3
# 主講課程及主要教學(xué)獎勵
data4 = tree.xpath('/html/body/div[4]/div/div[2]/div/div[5]/div/p//text()')
data['Main Courses and Teaching Awards'] = data4
# 主要科研成果及獎勵
data5 = tree.xpath('/html/body/div[4]/div/div[2]/div/div[6]/div/p//text()')
data['Main Research Achievements and Awards'] = data5
# 將數(shù)據(jù)轉(zhuǎn)換為DataFrame并添加到現(xiàn)有DataFrame中
new_dataframe = pd.DataFrame([data])
dataframe = pd.concat([dataframe, new_dataframe], ignore_index=True)
return dataframe
else:
print("請求失敗")
def scrape_url(url):
# 發(fā)起HTTP請求獲取網(wǎng)頁內(nèi)容
response = requests.get(url)
# 檢查請求是否成功
if response.status_code == 200:
# 使用lxml庫解析網(wǎng)頁內(nèi)容
html = response.text
tree = etree.HTML(html)
# 提取所有鏈接
links = tree.xpath('//*[@id="wp_content_w3_0"]//@href')
for link in links:
print("鏈接:", link)
return links
else:
print("請求失敗")
# 創(chuàng)建空的DataFrame來存儲導(dǎo)師信息
df = pd.DataFrame()
# 調(diào)用爬蟲函數(shù)
links = scrape_url("https://jsjxy.sdut.edu.cn/7534/list.htm")
for link in links:
print(link)
df = scrape_website(link, df)
time.sleep(1)
# 刪除JSON格式的數(shù)據(jù)
df = df.applymap(lambda x: ', '.join(x) if isinstance(x, list) else x)
# 將整理好的數(shù)據(jù)保存到Excel文件
df.to_excel("導(dǎo)師信息.xlsx", index=False)
print('########################### Over ###########################')
- 數(shù)據(jù)展示:
二、預(yù)處理及分析
2.1 數(shù)據(jù)預(yù)處理
2.1.1 考研信息預(yù)處理
- 刪除標題
- 刪除空數(shù)據(jù)
- 處理重復(fù)數(shù)據(jù)
- 篩選復(fù)試學(xué)院為"計算機科學(xué)與技術(shù)數(shù)據(jù)" | “計算機學(xué)院” 的數(shù)據(jù)
- 數(shù)據(jù)分別保存到三個Excel文件中,分別命名為“2020jsj”、“2021jsj”、“2022jsj”
import pandas as pd
# 讀取數(shù)據(jù)文件
data_path = "/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/"
file_names = ["2020year.xlsx", "2021year.xlsx", "2022year.xlsx"]
save_names = ["2020jsj.xlsx", "2021jsj.xlsx", "2022jsj.xlsx"]
for i in range(len(file_names)):
file_path = data_path + file_names[i]
save_path = data_path + save_names[i]
# 讀取Excel文件
df = pd.read_excel(file_path)
# 篩選條件
condition = ((df["復(fù)試學(xué)院"] == "計算機學(xué)院") | (df["復(fù)試學(xué)院"] == "計算機科學(xué)與技術(shù)學(xué)院"))
# 根據(jù)條件篩選數(shù)據(jù)
filtered_data = df[condition]
# 保存篩選后的數(shù)據(jù)到新的Excel文件
filtered_data.to_excel(save_path, index=False)
針對部分PDF轉(zhuǎn)Excel識別不規(guī)范處理:
- 根據(jù)“序號”一列將所有數(shù)據(jù)添加到新的excel表格中,如果“序號”對應(yīng)的數(shù)據(jù)為非數(shù)字或空則跳過
import pandas as pd
# 讀取原始Excel文件
file_path = '/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/2020year.xlsx'
df = pd.read_excel(file_path)
# 新建Excel文件
new_file_path = '/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/new_data.xlsx'
new_df = pd.DataFrame(columns=df.columns) # 使用原始Excel文件的表頭創(chuàng)建新的DataFrame
# 根據(jù)"序號"一列添加數(shù)據(jù)
for index, row in df.iterrows():
value = row['序號']
if pd.notnull(value) and str(value).isdigit():
new_df = new_df._append(row)
# 將數(shù)據(jù)保存到新的Excel文件
new_df.to_excel(new_file_path, index=False)
2.1.2 導(dǎo)師信息預(yù)處理
- 刪除空數(shù)據(jù)
- 處理重復(fù)數(shù)據(jù)
- 切分數(shù)據(jù)
import pandas as pd
import re
# 讀取Excel文件
file_path = '/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/導(dǎo)師信息.xlsx'
df = pd.read_excel(file_path)
# 刪除空數(shù)據(jù)
df = df.dropna(how='all')
# 處理重復(fù)數(shù)據(jù)
df = df.drop_duplicates()
# 創(chuàng)建新的Excel文件
output_file = '/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/導(dǎo)師信息處理后.xlsx'
writer = pd.ExcelWriter(output_file, engine='xlsxwriter')
# 處理每個導(dǎo)師的信息
for index, row in df.iterrows():
# 獲取導(dǎo)師名稱
teacher_name = row['Item 1']
# 創(chuàng)建以導(dǎo)師名稱命名的工作表
teacher_sheet = writer.book.add_worksheet(teacher_name)
# 添加表頭信息
headers = ['姓名', '職位', '主要學(xué)習(xí)工作簡歷', '主要研究方向', '社會兼職及榮譽稱號', '主講課程及主要教學(xué)獎勵',
'主要科研成果及獎勵']
for col_index, header in enumerate(headers):
teacher_sheet.write(0, col_index, header)
# 將每一列的數(shù)據(jù)按照“,”“、”“;”進行切分,并保存到新的工作表中
for col_index, value in enumerate(row):
if pd.notnull(value):
data_list = [x.strip() for x in re.split('[,、;]', str(value))]
for i, data in enumerate(data_list):
teacher_sheet.write(i + 1, col_index, data)
# 保存并關(guān)閉Excel文件
writer._save()
- 處理結(jié)果:
預(yù)處理后的數(shù)據(jù)仍有部分存在,手工處理后獲得數(shù)據(jù)plus
數(shù)據(jù)內(nèi)容:姓名、職位、主要學(xué)習(xí)工作簡歷、主要研究方向、社會兼職及榮譽稱號、主講課程
2.2 數(shù)據(jù)分析
三、可視化方法及結(jié)果
3.1 可視化方法
- 地理位置展示:pyecharts地圖展示工具
- 2020-2022年一志愿錄取成績
- 2020-2022年分數(shù)分布圖:初試成績、綜合面試成績、總成績(柱形圖)
- 2020-2022年分數(shù)分分布餅圖:初試成績、綜合面試成績、總成績(餅圖-輪播圖)
- 2020-2022年最低分、最高分對比:初試成績、綜合面試成績、總成績(箱線圖)
- 2020-2022年一志愿人數(shù)信息:參與一志愿人數(shù)、錄取人數(shù)變化圖(折線圖)
- 考試科目及內(nèi)容:Excel表格截圖
- 專業(yè)師資隊伍:研究方向(關(guān)系圖+詞云圖)
3.2 可視化結(jié)果展示
3.2.1 基本信息
- 地理位置
from pyecharts.charts import Geo
from pyecharts import options as opts
from pyecharts.globals import GeoType
def test_geo():
g = Geo()
# 選擇要顯示的地圖
g.add_schema(maptype="山東")
# 使用add_coordinate(name, lng, lat)添加坐標點和坐標名稱
g.add_coordinate('山東理工大學(xué)', 117.999601, 36.810315)
# 給上面的坐標點添加數(shù)據(jù),
data_pair = [('山東理工大學(xué)', 10)]
# 將數(shù)據(jù)添加到定義的地圖上
g.add('', data_pair, type_=GeoType.EFFECT_SCATTER, symbol_size=5)
# 設(shè)置樣式
g.set_series_opts(label_opts=opts.LabelOpts(is_show=True))
return g
g = test_geo()
# 渲染成html,保存在代碼文件的相同目錄下
g.render('坐標標注.html')
3.2.2 考研信息
2020-2022年分數(shù)分布圖:初試成績、綜合面試成績、總成績(柱形圖)
- 初試成績分布
import pandas as pd
from pyecharts.charts import Bar
from pyecharts import options as opts
# 文件路徑和文件名
file_path = "/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/"
file_names = ["2020jsj.xlsx", "2021jsj.xlsx", "2022jsj.xlsx"]
# 分數(shù)段
score_ranges = [225, 250, 275, 300, 325, 350, 375, 400, 425]
# 存儲每個分數(shù)段的人數(shù)
score_counts = [[0] * (len(score_ranges) - 1) for _ in range(len(file_names))]
# 遍歷文件進行統(tǒng)計
for idx, file_name in enumerate(file_names):
file = file_path + file_name
df = pd.read_excel(file)
# 獲取初試成績列數(shù)據(jù)
scores = df["初試成績"]
# 統(tǒng)計每個分數(shù)段的人數(shù)
for score in scores:
for i in range(len(score_ranges) - 1):
if score_ranges[i] <= score < score_ranges[i + 1]:
score_counts[idx][i] += 1
break
# 繪制柱狀圖
bar = (
Bar()
.add_xaxis([str(range_start) + '-' + str(range_end) for range_start, range_end in zip(score_ranges[:-1], score_ranges[1:])])
)
# 添加不同年份的數(shù)據(jù)系列
for idx, file_name in enumerate(file_names):
bar.add_yaxis(file_name[:-5], score_counts[idx], stack="stack{}".format(idx))
# 設(shè)置全局選項
bar.set_global_opts(
title_opts=opts.TitleOpts(title="初試成績分布"),
xaxis_opts=opts.AxisOpts(name="分數(shù)段"),
yaxis_opts=opts.AxisOpts(name="人數(shù)"),
)
# 渲染圖表
bar.render("score_distribution.html")
- 綜合面試成績分布
import pandas as pd
from pyecharts.charts import Bar
from pyecharts import options as opts
# 文件路徑和文件名
file_path = "/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/"
file_names = ["2020jsj.xlsx", "2021jsj.xlsx", "2022jsj.xlsx"]
# 分數(shù)段
score_ranges = list(range(70, 91, 2))
# 存儲每個分數(shù)段的人數(shù)
score_counts = [[0] * (len(score_ranges) - 1) for _ in range(len(file_names))]
# 遍歷文件進行統(tǒng)計
for idx, file_name in enumerate(file_names):
file = file_path + file_name
df = pd.read_excel(file)
# 獲取綜合面試成績列數(shù)據(jù)
scores = df["綜合面試成績"]
# 統(tǒng)計每個分數(shù)段的人數(shù)
for score in scores:
for i in range(len(score_ranges) - 1):
if score_ranges[i] <= score < score_ranges[i + 1]:
score_counts[idx][i] += 1
break
# 繪制柱狀圖
bar = (
Bar()
.add_xaxis([str(range_start) + '-' + str(range_end) for range_start, range_end in zip(score_ranges[:-1], score_ranges[1:])])
)
# 添加不同年份的數(shù)據(jù)系列
for idx, file_name in enumerate(file_names):
bar.add_yaxis(file_name[:-5], score_counts[idx], stack="stack{}".format(idx))
# 設(shè)置全局選項
bar.set_global_opts(
title_opts=opts.TitleOpts(title="綜合面試成績分布"),
xaxis_opts=opts.AxisOpts(name="分數(shù)段"),
yaxis_opts=opts.AxisOpts(name="人數(shù)"),
)
# 渲染圖表
bar.render("綜合面試成績分布.html")
- 總成績分布
import pandas as pd
from pyecharts.charts import Bar
from pyecharts import options as opts
# 文件路徑和文件名
file_path = "/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/"
file_names = ["2020jsj.xlsx", "2021jsj.xlsx", "2022jsj.xlsx"]
# 分數(shù)段
score_ranges = list(range(60, 82, 2))
# 存儲每個分數(shù)段的人數(shù)
score_counts = [[0] * (len(score_ranges) - 1) for _ in range(len(file_names))]
# 遍歷文件進行統(tǒng)計
for idx, file_name in enumerate(file_names):
file = file_path + file_name
df = pd.read_excel(file)
# 獲取總成績列數(shù)據(jù)
total_scores = df["總成績"]
# 統(tǒng)計每個分數(shù)段的人數(shù)
for score in total_scores:
for i in range(len(score_ranges) - 1):
if score_ranges[i] <= score < score_ranges[i + 1]:
score_counts[idx][i] += 1
break
# 繪制柱狀圖
bar = (
Bar()
.add_xaxis([str(range_start) + '-' + str(range_end) for range_start, range_end in zip(score_ranges[:-1], score_ranges[1:])])
)
# 添加不同年份的數(shù)據(jù)系列
for idx, file_name in enumerate(file_names):
bar.add_yaxis(file_name[:-5], score_counts[idx], stack="stack{}".format(idx))
# 設(shè)置全局選項
bar.set_global_opts(
title_opts=opts.TitleOpts(title="總成績分布"),
xaxis_opts=opts.AxisOpts(name="分數(shù)段"),
yaxis_opts=opts.AxisOpts(name="人數(shù)"),
)
# 渲染圖表
bar.render("總成績分布.html")
2020-2022年分數(shù)分分布餅圖:初試成績、綜合面試成績、總成績(餅圖)
- 初試成績
import pandas as pd
from pyecharts.charts import Pie, Timeline
from pyecharts import options as opts
# 文件路徑和文件名
file_path = "/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/"
file_names = ["2020jsj.xlsx", "2021jsj.xlsx", "2022jsj.xlsx"]
# 分數(shù)段
score_ranges = list(range(225, 425, 25)) # Updated score ranges
# 存儲每個分數(shù)段的人數(shù)
score_counts = [[0] * (len(score_ranges) - 1) for _ in range(len(file_names))]
# 遍歷文件進行統(tǒng)計
for idx, file_name in enumerate(file_names):
file = file_path + file_name
df = pd.read_excel(file)
# 獲取初試成績列數(shù)據(jù)
initial_scores = df["初試成績"]
# 統(tǒng)計每個分數(shù)段的人數(shù)
for score in initial_scores:
for i in range(len(score_ranges) - 1):
if score_ranges[i] <= score < score_ranges[i + 1]:
score_counts[idx][i] += 1
break
# 創(chuàng)建時間軸圖表
timeline = Timeline()
# 遍歷不同時間的數(shù)據(jù)
for idx, file_name in enumerate(file_names):
# 創(chuàng)建餅圖
pie = (
Pie()
.add(
series_name="分數(shù)段",
data_pair=[(str(range_start) + '-' + str(range_end), count) for range_start, range_end, count in zip(score_ranges[:-1], score_ranges[1:], score_counts[idx])],
radius="50%"
)
.set_series_opts(label_opts=opts.LabelOpts(formatter=": {c}"))
.set_global_opts(title_opts=opts.TitleOpts(title="初試成績分布"), legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_right="2%"))
)
# 添加當前時間的圖表到時間軸
timeline.add(pie, file_name[:-5])
# 渲染圖表
timeline.render("初試成績分布Pie.html")
- 綜合面試成績
import pandas as pd
from pyecharts.charts import Pie, Timeline
from pyecharts import options as opts
# 文件路徑和文件名
file_path = "/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/"
file_names = ["2020jsj.xlsx", "2021jsj.xlsx", "2022jsj.xlsx"]
# 分數(shù)段
score_ranges = list(range(60, 91, 5)) # Updated score ranges
# 存儲每個分數(shù)段的人數(shù)
score_counts = [[0] * (len(score_ranges) - 1) for _ in range(len(file_names))]
# 遍歷文件進行統(tǒng)計
for idx, file_name in enumerate(file_names):
file = file_path + file_name
df = pd.read_excel(file)
# 獲取綜合面試成績列數(shù)據(jù)
interview_scores = df["綜合面試成績"]
# 統(tǒng)計每個分數(shù)段的人數(shù)
for score in interview_scores:
for i in range(len(score_ranges) - 1):
if score_ranges[i] <= score < score_ranges[i + 1]:
score_counts[idx][i] += 1
break
# 創(chuàng)建時間軸圖表
timeline = Timeline()
# 遍歷不同時間的數(shù)據(jù)
for idx, file_name in enumerate(file_names):
# 創(chuàng)建餅圖
pie = (
Pie()
.add(
series_name="分數(shù)段",
data_pair=[(str(range_start) + '-' + str(range_end), count) for range_start, range_end, count in zip(score_ranges[:-1], score_ranges[1:], score_counts[idx])],
radius="50%"
)
.set_series_opts(label_opts=opts.LabelOpts(formatter=": {c}"))
.set_global_opts(title_opts=opts.TitleOpts(title="綜合面試成績分布"), legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_right="2%"))
)
# 添加當前時間的圖表到時間軸
timeline.add(pie, file_name[:-5])
# 渲染圖表
timeline.render("綜合面試成績分布Pie.html")
- 總成績
import pandas as pd
from pyecharts.charts import Pie, Timeline
from pyecharts import options as opts
# 文件路徑和文件名
file_path = "/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/"
file_names = ["2020jsj.xlsx", "2021jsj.xlsx", "2022jsj.xlsx"]
# 分數(shù)段
score_ranges = list(range(60, 80, 5)) # Updated score ranges
# 存儲每個分數(shù)段的人數(shù)
score_counts = [[0] * (len(score_ranges) - 1) for _ in range(len(file_names))]
# 遍歷文件進行統(tǒng)計
for idx, file_name in enumerate(file_names):
file = file_path + file_name
df = pd.read_excel(file)
# 獲取總成績列數(shù)據(jù)
total_scores = df["總成績"]
# 統(tǒng)計每個分數(shù)段的人數(shù)
for score in total_scores:
for i in range(len(score_ranges) - 1):
if score_ranges[i] <= score < score_ranges[i + 1]:
score_counts[idx][i] += 1
break
# 創(chuàng)建時間軸圖表
timeline = Timeline()
# 遍歷不同時間的數(shù)據(jù)
for idx, file_name in enumerate(file_names):
# 創(chuàng)建餅圖
pie = (
Pie()
.add(
series_name="分數(shù)段",
data_pair=[(str(range_start) + '-' + str(range_end), count) for range_start, range_end, count in zip(score_ranges[:-1], score_ranges[1:], score_counts[idx])],
radius="50%"
)
.set_series_opts(label_opts=opts.LabelOpts(formatter=": {c}"))
.set_global_opts(title_opts=opts.TitleOpts(title="總成績分布"), legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_right="2%"))
)
# 添加當前時間的圖表到時間軸
timeline.add(pie, file_name[:-5])
# 渲染圖表
timeline.render("總成績分布Pie.html")
2020-2022年一志愿人數(shù)信息:參與一志愿人數(shù)、錄取人數(shù)變化圖(折線圖)
import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Line
# 讀取Excel文件
df_2020 = pd.read_excel('/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/2020jsj.xlsx')
df_2021 = pd.read_excel('/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/2021jsj.xlsx')
df_2022 = pd.read_excel('/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/2022jsj.xlsx')
# 計算總?cè)藬?shù)和錄取人數(shù)
total_counts = [len(df_2020), len(df_2021), len(df_2022)]
admitted_counts = [
len(df_2020[df_2020['錄取結(jié)果'] == '擬錄取']),
len(df_2021[df_2021['錄取結(jié)果'] == '擬錄取']),
len(df_2022[df_2022['錄取結(jié)果'] == '擬錄取'])
]
# 創(chuàng)建折線圖
line = (
Line()
.add_xaxis(['2020', '2021', '2022'])
.add_yaxis('總?cè)藬?shù)', total_counts, markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(type_="average")]))
.add_yaxis('錄取人數(shù)', admitted_counts, markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(type_="average")]))
.set_global_opts(title_opts=opts.TitleOpts(title='總?cè)藬?shù)和錄取人數(shù)變化折線圖'),
yaxis_opts=opts.AxisOpts(name='人數(shù)'),
xaxis_opts=opts.AxisOpts(name='年份'))
)
# 保存為HTML文件并在瀏覽器中打開
line.render('/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/錄取人數(shù)變化.html')
2020-2022年最低分、最高分對比:初試成績、綜合面試成績、總成績(箱線圖)
import pandas as pd
import matplotlib.pyplot as plt
# 設(shè)置中文字體
plt.rcParams['font.sans-serif'] = 'SimHei'
# 讀取數(shù)據(jù)
data_2020 = pd.read_excel('/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/2020jsj.xlsx').dropna()
data_2021 = pd.read_excel('/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/2021jsj.xlsx').dropna()
data_2022 = pd.read_excel('/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/2022jsj.xlsx').dropna()
# 提取所需的列數(shù)據(jù)
score_2020 = data_2020['初試成績']
score_2021 = data_2021['初試成績']
score_2022 = data_2022['初試成績']
interview_2020 = data_2020['綜合面試成績']
interview_2021 = data_2021['綜合面試成績']
interview_2022 = data_2022['綜合面試成績']
total_2020 = data_2020['總成績']
total_2021 = data_2021['總成績']
total_2022 = data_2022['總成績']
# 繪制箱線圖
plt.figure(figsize=(10, 6))
# 初試成績對比圖
plt.subplot(1, 3, 1)
plt.boxplot([score_2020, score_2021, score_2022])
plt.xticks([1, 2, 3], ['2020', '2021', '2022'])
plt.title('初試成績')
# 綜合面試成績對比圖
plt.subplot(1, 3, 2)
plt.boxplot([interview_2020, interview_2021, interview_2022])
plt.xticks([1, 2, 3], ['2020', '2021', '2022'])
plt.title('綜合面試成績')
# 總成績對比圖
plt.subplot(1, 3, 3)
plt.boxplot([total_2020, total_2021, total_2022])
plt.xticks([1, 2, 3], ['2020', '2021', '2022'])
plt.title('總成績')
plt.tight_layout()
plt.show()
3.2.3 導(dǎo)師信息
- 導(dǎo)師對應(yīng)研究方向
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
# 設(shè)置中文字體
plt.rcParams['font.sans-serif'] = 'SimHei'
# 讀取Excel文件
file_path = '/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/導(dǎo)師信息處理plus.xlsx'
df = pd.read_excel(file_path, sheet_name=None)
# 創(chuàng)建空的有向圖
graph = nx.DiGraph()
# 添加導(dǎo)師和研究方向節(jié)點
for sheet_name, sheet_data in df.items():
tutor_name = sheet_name
research_directions = sheet_data['主要研究方向'].dropna().tolist()
# 添加導(dǎo)師節(jié)點
graph.add_node(tutor_name, node_type='tutor')
# 添加研究方向節(jié)點
for direction in research_directions:
graph.add_node(direction, node_type='research_direction')
# 添加導(dǎo)師與研究方向之間的邊
graph.add_edge(tutor_name, direction)
# 繪制關(guān)系圖
plt.figure(figsize=(12, 8))
pos = nx.spring_layout(graph, seed=42)
node_colors = {'tutor': 'lightblue', 'research_direction': 'lightgreen'}
nx.draw_networkx_nodes(graph, pos, node_color=[node_colors[graph.nodes[node]['node_type']] for node in graph.nodes()])
nx.draw_networkx_labels(graph, pos, font_size=10, font_color='black')
nx.draw_networkx_edges(graph, pos, arrowstyle='->', arrowsize=10)
plt.axis('off')
plt.show()
- 研究方向詞云圖
import pandas as pd
from collections import Counter
from pyecharts import options as opts
from pyecharts.charts import WordCloud
# 讀取Excel文件
file_path = '/Users/liuhao/MyProject/PycharmProject/DataVisualization/Project1/Data/導(dǎo)師信息處理plus.xlsx'
df = pd.read_excel(file_path, sheet_name=None)
# 統(tǒng)計研究方向出現(xiàn)的次數(shù)
research_directions = []
for sheet_name, sheet_data in df.items():
research_directions.extend(sheet_data['主要研究方向'].dropna().tolist())
research_direction_counts = Counter(research_directions)
# 生成詞云圖數(shù)據(jù)
wordcloud_data = [(key, value) for key, value in research_direction_counts.items()]
# 創(chuàng)建詞云圖
wordcloud = (
WordCloud()
.add(series_name="研究方向", data_pair=wordcloud_data, word_size_range=[20, 100])
.set_global_opts(title_opts=opts.TitleOpts(title="研究方向詞云圖"))
)
# 渲染詞云圖到HTML文件中
wordcloud.render("wordcloud.html")
文章來源:http://www.zghlxwxcb.cn/news/detail-520365.html
四、總結(jié)
本項目使用Python網(wǎng)絡(luò)爬蟲、Pandas、Pyecharts、matplotlib等工具完成對山東理工大學(xué)計算機科學(xué)與技術(shù)專業(yè)考研信息及導(dǎo)師信息的手機與展示。展現(xiàn)了2020-2022年共三年該專業(yè)的考研錄取信息并進行分析,
通過本項目,熟練掌握了對網(wǎng)絡(luò)數(shù)據(jù)的爬取,數(shù)據(jù)的可視化展示,能夠熟練運用Pandas等數(shù)據(jù)處理工具對數(shù)據(jù)進行簡單預(yù)處理,能夠熟練使用pyecharts、matplotlib等數(shù)據(jù)可視化工具,通過使用柱狀圖、折線圖、餅圖、箱線圖、關(guān)系圖、詞云圖等展示形式,對數(shù)據(jù)進行可視化展示。文章來源地址http://www.zghlxwxcb.cn/news/detail-520365.html
五、附錄
到了這里,關(guān)于【數(shù)據(jù)可視化】大作業(yè)(意向考研高校的數(shù)據(jù)可視化)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!