-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.py
More file actions
28 lines (15 loc) · 736 Bytes
/
analysis.py
File metadata and controls
28 lines (15 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import pandas as pd
df = pd.read_csv("student_preferences.csv")
df = df.assign(preferred_courses=df['preferred_courses'].str.split(';')).explode('preferred_courses')
course_demand = df['preferred_courses'].value_counts().reset_index()
course_demand.columns = ['course', 'student_count']
print(" Course Demand:")
print(course_demand)
gpa_stats = df.groupby('preferred_courses')['gpa'].agg(['mean', 'min', 'max']).reset_index()
gpa_stats.columns = ['course', 'avg_gpa', 'min_gpa', 'max_gpa']
print("\n GPA Stats by Course:")
print(gpa_stats)
course_analysis = pd.merge(course_demand, gpa_stats, on='course')
print("\n Final Course Analysis:")
print(course_analysis)
course_analysis.to_csv("course_analysis.csv", index=False)