Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use pandas to analyze students' final grades by python

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "how python uses pandas to analyze students 'final scores." In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

Install Pandas

Pandas is a fast, powerful, flexible and easy-to-use open source data analysis and manipulation tool built on top of the Python programming language. Pandas is a Numpy-based professional data analysis tool that can flexibly and efficiently process various data sets.

We use pip for installation (if you don't have it, check how to install pip yourself) The easiest way to install panda is to install it as part of Anaconda, which is mainly used for data analysis and scientific calculations. Instructions for installing source code, PyPI, ActivePython, various Linux distributions or development versions are also provided.

Of course, the most basic Python environment is still indispensable, if you are Linux or use Mac you do not need to install Python.

pip install pandas

analysis process

1. Read out the grade book of the class from excel file, and deal with the missing values.

2. According to the two columns of 'plus points' and 'minus points', calculate the usual scores.

3. The experimental report results were converted from ABCD to centesimal system, and the experimental results were counted. A is 90 points, B is 75 points, C is 60 points and D is 40 points.

4. Randomly generate hypothetical final grades, ranging from 40 to 100 points. Change your final grade to what you think you might get.

5. According to the usual score of 20%, experimental score of 30%, final score of 50% of the proportion of comprehensive score calculation.

6. Output your grades, lab grades, final grades and overall grades.

7. Count the number of people in the class's comprehensive scores [90,100],[80,89],[70,79],[60-69],[0,59] and draw a pie chart.

8. Save the complete score to the score.xlsx file and open excel to check that the output is correct.

complete instance

Preparation: Import required modules

import pandas as pdimport numpy as npimport randomfrom matplotlib import pyplot as plt

(1) Read out the grade book of the class students from the excel file and deal with the missing values.

df=pd.read_csv("Class 4 average score.csv",encoding="gbk")df=df.rename(columns={"ID":"student number"})#rename column ID df.set_index("name",inplace=True)#use name as indexdf=df.fillna(method="backfill")#handle missing values

(2) According to the two columns of 'plus points' and 'minus points', calculate the usual scores.

df["average score"]=df["average score"]-df["minus score"]df=df.drop("minus score",axis=1)#Delete Column

(3) Convert the experimental report scores from ABCD to 100-point system, and count the experimental scores. A is 90 points, B is 75 points, C is 60 points and D is 40 points.

def m(x):#2 Convert ABCD to its corresponding fraction if x=="A": return 90 if x=="B": return 75 if x=="C": return 60 if x=="D": return 40df["1st Lab Report"]=df. 1st Lab Report.map(m)df["2nd Lab Report"]=df. 2nd Lab Report.map(m)df["3rd Lab Report"]=df. 3rd Lab Report.map(m)

(4) Randomly generate hypothetical final grades, ranging from 40 to 100 points. Change your final grade to what you think you might get.

def cj(x): return random. randomt (40,100)df["Final Grade"]=""df["Final Grade"]=df. Final Grade.map(cj)df

(5) Calculate the comprehensive score according to the proportion of 20% of the usual score, 30% of the experimental score and 50% of the final score.

df["Overall Score"]=df["Final Score"]*0.5+df["Regular Score"]*0.2+df["First Lab Report"]*0.1+\ df["Second Experimental Report"]*0.1+df["Third Experimental Report"]*0.1df

(6) Output your usual grades, laboratory grades, final grades and comprehensive grades.

df[df. name =='just for you220']

(7) Count the number of people in the class's comprehensive scores [90,100],[80,89],[70,79],[60-69],[0,59], and draw a pie chart.

y=pd.cut(df ['overall score'],bins=[0,60,70,80,90,100],\ labels=['0- 59','60- 69','70- 79','80- 89','90- 100'])#Interval a=y.value_counts()#Statistical Interval Number print(a)plt.rcParams['font.sans-serif']=['SimHei']a.plot(kind='pie',title=' Student Score Interval Statistics')

(8) Save the complete score to the score.xlsx file and open Excel to check whether the output is correct.

Save results as.xlsx file

df.to_excel(excel_writer="score.xlsx",index=False,encoding='utf-8')

Open the.xlsx file you just saved and see if the results are correct

pd.read_excel("score.xlsx")"python how to use pandas to analyze students 'final grades" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report