龙空技术网

用Python数据分析山东高考一分一段表

龙骑士洞察 40

前言:

如今各位老铁们对“python求峰值”大约比较重视,兄弟们都想要知道一些“python求峰值”的相关资讯。那么小编也在网摘上收集了一些关于“python求峰值””的相关资讯,希望看官们能喜欢,同学们快快来了解一下吧!

学习数据分析的有效方法是从应用中学习,而非埋头在各种手册和文档中。高考志愿刚填报不久,我们以山东高考的一分一段线来掌握Pandas数据分析的基本技能。

准备数据

首次从山东考试院拿到“2023夏季高考文化成绩一分一段表”。

2023夏季高考一分一段表

摘取其中的“分数段”,“本段人数”和“累计人数”。

不分科的累计人数

概览读取的数据

我们的数据分析要用到python的numpy和pandas,用read_excel读取数据:

import numpy as npimport pandas as pdimport matplotlib.pyplot as pltplt.style.use('bmh')df = pd.read_excel("~/Downloads/高考/山东2023高考分数分布.xlsx")

看一眼读取的数据:

In [2]: dfOut[2]:     Unnamed: 0  分数段  本段人数    累计人数0             1  695    15      861             2  694    14     1002             3  693    12     1123             4  692    17     1294             5  691    19     148..          ...  ...   ...     ...541         542  154    43  662004542         543  153    61  662065543         544  152    49  662114544         545  151    39  662153545         546  150    46  662199[546 rows x 4 columns]

先从整体上把握数据的结构和框架:

df.shape# (545,4)

“一分一段表”是545行又4列。

In [4]: df.columnsOut[4]: Index(['Unnamed: 0', '分数段', '本段人数', '累计人数'], dtype='object')In [5]: df.indexOut[5]: RangeIndex(start=0, stop=546, step=1)

全局的数据描述:

Out[6]:Unnamed: 0                   分数段         本段人数           累计人数count  546.000000  546.000000   546.000000     546.000000mean   273.500000  422.500000  1212.688645  338954.412088std    157.760895  157.760895   863.292144  253289.462712min      1.000000  150.000000    12.000000      86.00000025%    137.250000  286.250000   341.000000   62888.25000050%    273.500000  422.500000  1190.000000  356720.50000075%    409.750000  558.750000  2066.000000  606735.500000max    546.000000  695.000000  2606.000000  662199.000000
绘图分析数据

一分一段表分数分布如图:

plt.plot(df["分数段"], df['本段人数'])

一分一段表分布

读图可知分数主要聚集于400分到500分的分数段。但观察最高的峰值点很费劲,再将其标注出来。

plt.plot(df["分数段"], df['本段人数'])max_population = df["本段人数"].max()max_score = df.loc[df["本段人数"].idxmax(), "分数段"]plt.scatter(max_score, max_population, marker="h", s=50, color="red")

标注峰值点

峰值标注后看得是一目了然,绘图的结构也近似于正态分布。

直方图分析

更为直观的方法是直方图分析,一眼便能掌握各分数段的分布情况。

# Create the histogramplt.hist(df['分数段'], weights=df['本段人数'], color='steelblue', edgecolor='white')plt.xlabel('Score')plt.ylabel('Population')plt.title('Population vs. Score')plt.show()

直方图分布

读图可知,考生分数集中于450~500分之间。但此时的bins调用的是numpy.histgram的自动计算间隔,因此柱状图之间的分割线没有正好落在整数上。

调整bins之后的代码如下:

bins = range(100, 701, 50)# Create the histogramplt.hist(df['分数段'], bins=bins ,weights=df['本段人数'], color='steelblue', edgecolor='white')plt.xlabel('Score')plt.ylabel('Population')plt.title('Population vs. Score')plt.show()

每50分为一个区间

此时就看得分明了,大部分考生的分数并不高,主要在450到500之间。

收尾

学习数据分析,要从分析日常生活的数据着手,不然总是纸上谈兵。

标签: #python求峰值 #ubuntupython2712