-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.py
More file actions
120 lines (95 loc) · 2.94 KB
/
analysis.py
File metadata and controls
120 lines (95 loc) · 2.94 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv("student_data.csv")
print(df.head())
print("\n----Basic Info----")
print(df.info())
print("\n----Summary Statistics---")
print(df.describe())
print("\n---- Missing Values----")
print(df.isnull().sum())
print("Total Students:", len(df))
print(df.columns)
duplicates = df.duplicated().sum()
print("\nDuplicate rows found:", duplicates)
df = df.drop_duplicates()
print("\nNegative values check:")
print((df[["Study hours", 'Attendance', 'Marks']] < 0).sum())
print("\nFill Missing values")
df['Study hours'] = df['Study hours'].fillna(df['Study hours'].mean())
df['Attendance'] = df["Attendance"].fillna(df['Attendance'].mean())
df['Marks'] = df['Marks'].fillna(df['Marks'].mean())
# Performance Category
def Categorize_marks(m):
if m >= 75:
return "High"
elif m >= 50:
return "Medium"
else:
return "Low"
df["performance_category"] = df["Marks"].apply(Categorize_marks)
print("\nPerformance category distribution:")
print(df["performance_category"].value_counts())
# Basic Analysis
print("Average Study hours:", df["Study hours"].mean())
print("Average Attendance:", df["Attendance"].mean())
print("Average Marks:", df["Marks"].mean())
print("\nGender Wise Count:")
print(df['Gender'].value_counts())
# Relationship analysis
print("\n---Correlation with marks---")
print(df.corr(numeric_only=True))
# visualization
numeric_df = df.select_dtypes(include=['int64', 'float64'])
# correlation heatmap
plt.figure(figsize=(6, 4))
sns.heatmap(numeric_df.corr(), annot=True, cmap="Blues")
plt.title("Correlation heatmap")
plt.show()
# Study Hours vs Marks (Scatter + Trendline)
plt.figure(figsize=(6, 4))
sns.regplot(x='Study hours', y='Marks', data=df)
plt.xlabel("Study Hours")
plt.ylabel("Marks")
plt.title("Study Hours vs Marks (Trendline)")
plt.show()
# Attendance vs Marks (Scatter + Trendline)
plt.figure(figsize=(6, 4))
sns.regplot(x='Attendance', y='Marks', data=df)
plt.xlabel("Attendance")
plt.ylabel("Marks")
plt.title("Attendance vs Marks (Trendline)")
plt.show()
# Boxplots
plt.figure(figsize=(6, 4))
sns.boxplot(x='Gender', y="Marks", data=df)
plt.title("Marks Distribution by Gender")
plt.xlabel("Gender")
plt.ylabel("Marks")
plt.show()
plt.figure(figsize=(6, 4))
sns.boxplot(x='performance_category', y="Marks", data=df)
plt.title("Marks Distribution by Performance Category")
plt.xlabel("Performance Category")
plt.ylabel("Marks")
plt.show()
# ---- Histograms & Distribution Plots ----
plt.figure(figsize=(6,4))
sns.histplot(df["Marks"], kde=True)
plt.title("Marks Distribution")
plt.xlabel("Marks")
plt.ylabel("Count")
plt.show()
plt.figure(figsize=(6,4))
sns.histplot(df["Study hours"], kde=True)
plt.title("Study Hours Distribution")
plt.xlabel("Study Hours")
plt.ylabel("Count")
plt.show()
plt.figure(figsize=(6,4))
sns.histplot(df["Attendance"], kde=True)
plt.title("Attendance Distribution")
plt.xlabel("Attendance")
plt.ylabel("Count")
plt.show()