Week2 : Assignments¶
Data Visualization¶
XI Science Results¶
In [12]:
import pandas as pd
import matplotlib.pyplot as plt
PASS_MARKS = 40
subjects = [
"Physics",
"Chemistry",
"Maths", # Corrected from "Mathematics"
"Biology",
"English I" # Corrected from "English"
]
df = pd.read_csv("datasets/11science.csv")
df = df.drop(0).reset_index(drop=True)
for subject in subjects:
# Use 'coerce' to convert non-numeric values (e.g., text for "Absent") to NaN
df[subject] = pd.to_numeric(df[subject], errors='coerce')
pass_students = []
for subject in subjects:
# Count students with marks >= PASS_MARKS. NaN values are treated as False (not passed).
count = (df[subject] >= PASS_MARKS).sum()
pass_students.append(count)
plt.figure(figsize=(10, 6))
plt.scatter(subjects, pass_students, color='skyblue', s=100)
plt.xlabel("Subjects")
plt.ylabel("Number of Pass Students")
plt.title(f"Subject-wise Pass Students (Pass Mark: {PASS_MARKS})")
plt.grid(axis='y', linestyle='--')
plt.tight_layout()
plt.show()
In [ ]: