需要源碼和數(shù)據(jù)集請點贊關(guān)注收藏后評論區(qū)留言私信~~~
下面對學生成句和表現(xiàn)等數(shù)據(jù)可視化分析
1:導入模塊
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['simhei']
plt.rcParams['font.serif'] = ['simhei']
import warnings
warnings.filterwarnings('ignore')
2:獲取數(shù)據(jù) 并打印前四行
from matplotlib.font_manager import FontProperties
myfont=FontProperties(fname=r'C:\Windows\Fonts\SimHei.ttf',size=12)
sns.set(font=myfont.get_name())
df = pd.read_csv('.\data\StudentPerformance.csv')
df.head(4)
?屬性列表對應含義如下
Gender? 性別
Nationality? 國籍
PlaceofBirth 出生地
Stageid 學校級別
Gradeid 年級
Sectionid? 班級
Topic 科目
semester 學期
ralation 孩子家庭教育負責人
raisedhands 學生上課舉手的次數(shù)
announcementviews 學生瀏覽在線課件的次數(shù)
discussion 學生參與課堂討論的次數(shù)
parentanswersurvey 家長是否填了學校的問卷
parentschoolsatisfaction 家長對于學校的滿意度
studentabsencedays? ? ? ? ?學生缺勤天數(shù)
3:數(shù)據(jù)可視化分析
接下來線修改表列名 換成中文
df.rename(columns={'gender':'性別','NationalITy':'國籍','PlaceofBirth':'出生地',
'StageID':'學段','GradeID':'年級','SectionID':'班級','Topic':'科目',
'Semester':'學期','Relation':'監(jiān)管人','raisedhands':'舉手次數(shù)',
'VisITedResources':'瀏覽課件次數(shù)','AnnouncementsView':'瀏覽公告次數(shù)',
'Discussion':'討論次數(shù)','ParentAnsweringSurvey':'父母問卷',
'ParentschoolSatisfaction':'家長滿意度','StudentAbsenceDays':'缺勤次數(shù)',
'Class':'成績'},inplace=True)
df.replace({'lowerlevel':'小學','MiddleSchool':'中學','HighSchool':'高中'},inplace=True)
df.columns
?顯示學期和學段的取值
然后修改數(shù)據(jù)
df.replace({'lowerlevel':'小學','MiddleSchool':'中學','HighSchool':'高中'},inplace=True)
df['性別'].replace({'M':'男','F':'女'},inplace=True)
df['學期'].replace({'S':'春季','F':'秋季'},inplace=True)
df.head(4)
?查看空缺數(shù)據(jù)情況
df.isnull().sum()
查看數(shù)據(jù)統(tǒng)計情況
?
?然后按成績繪制計數(shù)柱狀圖
sns.countplot(x = '成績', order = ['L', 'M', 'H'], data = df, linewidth=2,edgecolor=sns.color_palette("dark",4))
?接著按性別繪制計數(shù)柱狀圖
sns.countplot(x = '性別', order = ['女', '男'],data = df)
?按科目繪制計數(shù)柱狀圖
sns.set_style('whitegrid')
sns.set(rc={'figure.figsize':(16,8)},font=myfont.get_name(),font_scale=1.5)
sns.countplot(x = '科目', data = df)
?按科目繪制不同成績的計數(shù)柱狀圖
按性別和成績繪制計數(shù)柱狀圖
sns.countplot(x = '性別', hue = '成績',data = df, order = ['女', '男'], hue_order = ['L', 'M', 'H'])
按班級查看成績分布比例
sns.countplot(x = '班級', hue='成績', data=df, hue_order = ['L','M','H'])
# 從這里可以看出雖然每個班人數(shù)較少,但是沒有那個班優(yōu)秀的人數(shù)的比例比較突出,這個特征可以刪除
?分析4個表現(xiàn)和成績的相關(guān)性
# 了解四個課堂和課后表現(xiàn)與成績的相關(guān)性
fig, axes = plt.subplots(2,2,figsize=(14,10))
sns.barplot(x='成績', y='瀏覽課件次數(shù)',data=df,order=['L','M','H'],ax=axes[0,0])
sns.barplot(x='成績', y='瀏覽公告次數(shù)',data=df,order=['L','M','H'],ax=axes[0,1])
sns.barplot(x='成績', y='舉手次數(shù)',data=df,order=['L','M','H'],ax=axes[1,0])
sns.barplot(x='成績', y='討論次數(shù)',data=df,order=['L','M','H'],ax=axes[1,1])
# 在sns.barplot中,默認的計算方式為計算平均值
?分析不同成績學生的討論情況
# 了解舉手次數(shù)與成績之間的相關(guān)性
sns.set(rc={'figure.figsize':(8,6)},font=myfont.get_name(),font_scale=1.5)
sns.boxplot(x='成績',y='討論次數(shù)',data=df,order=['L','M','H'])
?分析舉手次數(shù)和參加討論次數(shù)的相關(guān)性
# 了解四個課堂后量化表現(xiàn)之間的相關(guān)性
# fig,axes = plt.subplots(2,1,figsize=(10,10))
sns.regplot(x='舉手次數(shù)',y='討論次數(shù)',order =4,data=df)
# sns.regplot(x='瀏覽公告次數(shù)',y='瀏覽課件次數(shù)',order=4,data=df,ax=axes[1]) ,ax=axes[0]
?分析瀏覽課件次數(shù) 舉手次數(shù) 瀏覽公告次數(shù) 討論次數(shù)之間的相關(guān)性
# Correlation Matrix 相關(guān)性矩陣
corr = df[['瀏覽課件次數(shù)','舉手次數(shù)','瀏覽公告次數(shù)','討論次數(shù)']].corr()
corr
?最后將相關(guān)矩陣用熱力圖可視化顯示
文章來源:http://www.zghlxwxcb.cn/news/detail-435528.html
# Correlation Matrix Visualization 相關(guān)性可視化
sns.heatmap(corr,xticklabels=corr.columns,yticklabels=corr.columns)
?創(chuàng)作不易 覺得有幫助請點贊關(guān)注收藏~~~文章來源地址http://www.zghlxwxcb.cn/news/detail-435528.html
到了這里,關(guān)于【數(shù)據(jù)分析與可視化】利用Python對學生成績進行可視化分析實戰(zhàn)(附源碼)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!