0% found this document useful (0 votes)
7 views2 pages

Student Performance Grade Analysis

The document is a Python script for analyzing student performance using grades based on mid-semester scores, internal marks, and attendance. It calculates overall grades and visualizes the results through bar and pie charts. The script allows users to select different options to display grade distributions and exits upon user request.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Student Performance Grade Analysis

The document is a Python script for analyzing student performance using grades based on mid-semester scores, internal marks, and attendance. It calculates overall grades and visualizes the results through bar and pie charts. The script allows users to select different options to display grade distributions and exits upon user request.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

StudentPerformanceAnalysis.

py

1 import pandas as pd
2 import numpy as np
3 import [Link] as plt
4
5 # Function to calculate grades based on score
6 def calculate_grade(score):
7 if score >= 91:
8 return 'A+'
9 elif score >= 81:
10 return 'A'
11 elif score >= 71:
12 return 'B+'
13 elif score >= 61:
14 return 'B'
15 elif score >= 51:
16 return 'C+'
17 elif score >= 41:
18 return 'C'
19 elif score >= 31:
20 return 'D'
21 elif score < 33:
22 return 'F'
23
24 # Function to calculate overall grade
25 def calculate_overall_gr­
ade(row):
26 mid_sem_avg = row['Mid Sem Avg']
27 internal = row['Internal Marks']
28 attendance = row['Attendance Percentage']
29 overall_score = (0.4 * (mid_sem_avg / 30 * 100)) + (0.4 * (internal / 15 * 100)) + (0.2 *
attendance)
30 return calculate_grade(overall_score)
31
32 def main():
33 # Use the .csv file present in the same directory
34 file_path = 'student_data.csv' # Replace with your actual file name
35 data = pd.read_csv(file_path)
36
37 # Calculate average of best 2 mid semester marks
38 data['Mid Sem Avg'] = data[['Mid Sem 1', 'Mid Sem 2', 'Mid Sem 3']].apply(lambda x:
[Link](sorted(x, reverse=True)[:2]), axis=1)
39
40 # Calculate attendance percentage
41 data['Attendance Percentage'] = (data['Days Attended'] / data['Total Days']) * 100
42
43 # Calculate overall grades
44 data['Overall Grade'] = [Link](calculate_overall_gr­
ade, axis=1)
45
46 # Map grades for each category
47 data['Mid Sem Grade'] = data['Mid Sem Avg'].apply(lambda x: calculate_grade((x / 30) * 100))
48 data['Internal Grade'] = data['Internal Marks'].apply(lambda x: calculate_grade((x / 15) * 100))
49 data['Attendance Grade'] = data['Attendance Percentage'].apply(calculate_grade)
50
51 grade_order = ['A+', 'A', 'B+', 'B', 'C+', 'C', 'D', 'F']
52
53 # Display options to the user
54 while True:
55 print("\nOptions:")
56 print("1. Display grades based on Mid Semester Scores")
57 print("2. Display grades based on Internal Marks")
58 print("3. Display grades based on Attendance")
59 print("4. Display overall grades")
60 print("5. Exit")
61
62 choice = int(input("Enter your choice: "))
63
64 if choice in [1, 2, 3, 4]:
65 if choice == 1:
66 grade_column = 'Mid Sem Grade'
67 title = 'Grades Distribution Based on Mid Semester Scores'
68 color = 'skyblue'
69 elif choice == 2:
70 grade_column = 'Internal Grade'
71 title = 'Grades Distribution Based on Internal Marks'
72 color = 'lightgreen'
73 elif choice == 3:
74 grade_column = 'Attendance Grade'
75 title = 'Grades Distribution Based on Attendance'
76 color = 'lightcoral'
77 elif choice == 4:
78 grade_column = 'Overall Grade'
79 title = 'Overall Grades Distribution'
80 color = 'gold'
81
82 grade_counts = data[grade_column].value_counts().reindex(grade_order, fill_value=0)
83
84 # Bar chart
85 [Link](figsize=(10, 6))
86 grade_counts.plot(kind='bar', color=color)
87 [Link](title)
88 [Link]('Grades')
89 [Link]('Number of Students')
90 [Link]().yaxis.set_major_locator([Link](integer=True))
91 [Link](rotation=0)
92 [Link]()
93
94 # Pie chart
95 [Link](figsize=(8, 8))
96 grade_counts.plot(kind='pie', autopct='%1.1f%%', colors=[Link])
97 [Link](title)
98 [Link]('')
99 [Link]()
100
101 elif choice == 5:
102 print("Exiting...")
103 break
104
105 else:
106 print("Invalid choice. Please try again.")
107
108 if __name__ == "__main__":
109 main()
110

You might also like