IP12 gargi

Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

SAINT SOLDIER PUBLIC SCHOOL

Bhagwan Das Road, C-Scheme, 302001, Jaipur

An Informatics Practices Project (2024-25)

“Student Exam Marks


Data Analysis”

SUBMITTED BY : GARGI OJHA


CLASS : XII-A
SUBMITTED TO : MRS. MEENAKSHI KUTTY
DESIGNATION : HOD INFORMATICS PRACTICES
ACKNOWLEDEGMENT

I would like to express my special thanks of gratitude to


my teacher Mrs. Meenakshi Kutty (HOD of
Informatics Practices), as well as our Principal Mrs.
Sonal Sharma, who gave me the golden opportunity to
work on this wonderful project on the topic Student
Exam Marks Data Analysis. This project helped me in
conducting extensive research and learning so many
new things. I am really grateful for their guidance and
support.
Secondly, I would also like to thank my parents and
friends for their constant encouragement and help in
finalizing the project within the limited time frame. Last
but not least, I would like to give credit to my partner,
Rajdeep Singh Chauhan, for her collaborative efforts and
teamwork in completing this project.

Gargi Ojha
XII A
A ABOUT PYTHON

Python is a popular and easy-to-learn programming


language. It was created by Guido van Rossum in 1991.
Python is known for its simple and readable code, which
makes it a great choice for beginners. It’s used for a wide
range of tasks, from building websites and apps to
analyzing data and even creating artificial intelligence.
One of the reasons Python is so widely used is because it
has a large collection of libraries and tools that make
programming easier and faster. Libraries like NumPy,
Pandas, and Matplotlib are commonly used for tasks
such as data analysis and creating graphs.
Python is also an open-source language, meaning it’s
free to use and has a large community of developers
who help improve it. Whether you're a beginner or an
expert, Python is a great language to work with due to
its simplicity and versatility.
ABOUT CSV

A comma-separated-values (CSV) file is a delimited text


file that uses a comma as a filed separator is the source
of the name for this file format. A CSV file typically
stores tabular data in plain text and numbers. Main
advantage of using CSV files is that this format is
supported by almost all spreadsheet and database
management systems, including Apple numbers,
Microsoft Excel, Apache open office calc. CSV format is
supported by libraries for many programming languages
(like python, C , Java etc.)
PREFACE

This project is a Student Exam Marks Management System built


in Python to streamline managing student data. It allows adding,
updating, searching, deleting, and analyzing student records. The
system uses Pandas for data handling, Matplotlib for graphing, and
FPDF for generating PDF reports, making it an effective tool for
managing and visualizing student marks.

I hope this project meets its intended purpose and proves useful in
educational settings.

Functions Used
 addStudent(): Adds a new student record.
 updateStudent(): Updates student details.
 viewAllRecords(): Displays all records.
 searchStudentByID(): Searches by student ID.
 searchBySubject(): Finds students by subject.
 deleteStudent(): Deletes a student’s record.
 averageMarksBySubject(): Calculates subject average marks.
 highestScorerBySubject(): Finds highest scorer in a subject.
 barChartMarks(): Creates a bar chart of marks.
 saveToPDF(): Generates a PDF report.
 exportToCSV(): Exports data to CSV.
MENU

1. Add Student
2. Update Student
3. View All Records
4. Search by ID
5. Search by Subject
6. Delete Student
7. Average Marks by Subject
8. Highest Scorer by Subject
9. Count Students by Subject
10. Students Above Threshold
11. Save Subject Data to CSV
12. Export All Data to CSV
13. Bar Chart of Marks
14. Line Graph of Marks
15. Combined Bar Graph
16. Histogram of Marks
17. Save to PDF Report
18. Exit
CODING
import pandas as pd
import matplotlib.pyplot as plt
from fpdf import FPDF

# Load or Initialize DataFrame


try:
df = pd.read_csv("ExamData.csv")
except FileNotFoundError:
df = pd.DataFrame(columns=["Student ID", "Name", "Subject", "Marks"])

# Function Definitions (12 DataFrame + 4 Graphs + Utilities)

# 1. Add a new student record


def addStudent():
global df
student_id = int(input("Enter Student ID: "))
name = input("Enter Student Name: ")
subject = input("Enter Subject: ")
marks = int(input("Enter Marks: "))
new_data = pd.DataFrame([[student_id, name, subject, marks]], columns=["Student ID",
"Name", "Subject", "Marks"])
df = pd.concat([df, new_data], ignore_index=True)
print("New student record added successfully!")

# 2. Update an existing student record


def updateStudent():
global df
student_id = int(input("Enter Student ID to update: "))
if student_id in df["Student ID"].values:
name = input("Enter new Student Name (leave blank to keep existing): ")
subject = input("Enter new Subject (leave blank to keep existing): ")
marks = input("Enter new Marks (leave blank to keep existing): ")
if name:
df.loc[df["Student ID"] == student_id, "Name"] = name
if subject:
df.loc[df["Student ID"] == student_id, "Subject"] = subject
if marks:
df.loc[df["Student ID"] == student_id, "Marks"] = int(marks)
print("Student record updated successfully!")
else:
print("Student ID not found.")
# 3. View all student records
def viewAllRecords():
print("\nAll Student Records:")
print(df)

# 4. Search for a student by ID


def searchStudentByID():
student_id = int(input("Enter Student ID to search: "))
record = df[df["Student ID"] == student_id]
if not record.empty:
print("Student Record Found:")
print(record)
else:
print("No record found with the given Student ID.")

# 5. Search for students by subject


def searchBySubject():
subject = input("Enter Subject to search: ")
records = df[df["Subject"].str.lower() == subject.lower()]
if not records.empty:
print("Records Found:")
print(records)
else:
print("No records found for the given subject.")

# 6. Delete a student record


def deleteStudent():
global df
student_id = int(input("Enter Student ID to delete: "))
if student_id in df["Student ID"].values:
df = df[df["Student ID"] != student_id]
print("Record deleted successfully!")
else:
print("Student ID not found.")

# 7. Calculate average marks for a subject


def averageMarksBySubject():
subject = input("Enter Subject to calculate average marks: ")
avg_marks = df[df["Subject"].str.lower() == subject.lower()]["Marks"].mean()
if not pd.isna(avg_marks):
print(f"Average Marks for {subject}: {avg_marks:.2f}")
else:
print("No data available for the given subject.")
# 8. Find the highest scorer in a subject
def highestScorerBySubject():
subject = input("Enter Subject to find the highest scorer: ")
records = df[df["Subject"].str.lower() == subject.lower()]
if not records.empty:
top_scorer = records.loc[records["Marks"].idxmax()]
print(f"Highest Scorer in {subject}:")
print(top_scorer)
else:
print("No data available for the given subject.")

# 9. Count total students in a subject


def countStudentsBySubject():
subject = input("Enter Subject: ")
count = df[df["Subject"].str.lower() == subject.lower()].shape[0]
print(f"Total students in {subject}: {count}")

# 10. Display data for students scoring above a threshold


def studentsAboveThreshold():
threshold = int(input("Enter marks threshold: "))
records = df[df["Marks"] > threshold]
if not records.empty:
print("Students scoring above threshold:")
print(records)
else:
print("No students found with marks above the given threshold.")

# 11. Save data for a specific subject to a CSV file


def saveSubjectData():
subject = input("Enter Subject: ")
records = df[df["Subject"].str.lower() == subject.lower()]
if not records.empty:
filename = f"{subject}_data.csv"
records.to_csv(filename, index=False)
print(f"Data for {subject} saved to {filename}.")
else:
print("No data found for the given subject.")

# 12. Export entire data to CSV


def exportToCSV():
global df
df.to_csv("ExamData.csv", index=False)
print("Data saved to ExamData.csv.")
# Graphical Functions (4 graphs)

# 13. Bar chart of marks by student


def barChartMarks():
df.plot(x="Name", y="Marks", kind="bar", title="Marks Bar Chart", color="navy")
plt.xlabel("Student Name")
plt.ylabel("Marks")
plt.xticks(rotation=45)
plt.show()

# 14. Line graph of student marks


def lineGraphMarks():
df.sort_values("Marks", inplace=True)
plt.plot(df["Name"], df["Marks"], marker="o", linestyle="-", color="green", label="Marks")
plt.title("Student Marks Line Graph")
plt.xlabel("Student Name")
plt.ylabel("Marks")
plt.xticks(rotation=45)
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()

# 15. Combined bar graph for subject averages and highest marks
def combinedBarGraph():
avg_marks = df.groupby("Subject")["Marks"].mean()
highest_marks = df.groupby("Subject")["Marks"].max()
x = avg_marks.index
x_labels = range(len(x))
plt.bar(x_labels, avg_marks, width=0.4, label="Average Marks", color="lightblue",
align="center")
plt.bar([p + 0.4 for p in x_labels], highest_marks, width=0.4, label="Highest Marks",
color="navy")
plt.xticks([p + 0.2 for p in x_labels], x, rotation=45)
plt.xlabel("Subjects")
plt.ylabel("Marks")
plt.title("Subject-wise Average and Highest Marks")
plt.legend()
plt.tight_layout()
plt.show()

# 16. Histogram of marks distribution


def histogramMarks():
df["Marks"].plot(kind="hist", bins=5, title="Marks Distribution", color="orange")
plt.xlabel("Marks")
plt.ylabel("Frequency")
plt.show()

# Utility Functions

# 17. Save data to PDF report


def saveToPDF():
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size=12)
pdf.cell(200, 10, txt="Exam Marks Report", ln=True, align="C")
for i in range(len(df)):
record = df.iloc[i]
pdf.cell(200, 10, txt=f"{record.to_dict()}", ln=True)
pdf.output("ExamReport.pdf")
print("Data saved to ExamReport.pdf.")

# Menu
def menu():
while True:
print("\n---- Exam Marks Management ----")
print("1. Add Student")
print("2. Update Student")
print("3. View All Records")
print("4. Search by ID")
print("5. Search by Subject")
print("6. Delete Student")
print("7. Average Marks by Subject")
print("8. Highest Scorer by Subject")
print("9. Count Students by Subject")
print("10. Students Above Threshold")
print("11. Save Subject Data to CSV")
print("12. Export All Data to CSV")
print("13. Bar Chart of Marks")
print("14. Line Graph of Marks")
print("15. Combined Bar Graph")
print("16. Histogram of Marks")
print("17. Save to PDF Report")
print("18. Exit")

choice = int(input("Enter your choice: "))


if choice == 1:
addStudent()
elif choice == 2:
updateStudent()
elif choice == 3:
viewAllRecords()
elif choice == 4:
searchStudentByID()
elif choice == 5:
searchBySubject()
elif choice == 6:
deleteStudent()
elif choice == 7:
averageMarksBySubject()
elif choice == 8:
highestScorerBySubject()
elif choice == 9:
countStudentsBySubject()
elif choice == 10:
studentsAboveThreshold()
elif choice == 11:
saveSubjectData()
elif choice == 12:
exportToCSV()
elif choice == 13:
barChartMarks()
elif choice == 14:
lineGraphMarks()
elif choice == 15:
combinedBarGraph()
elif choice == 16:
histogramMarks()
elif choice == 17:
saveToPDF()
elif choice == 18:
print("Exiting...")
break
else:
print("Invalid choice! Please try again.")

# Run the program


menu()
OPTION 1
Program >>>
# 1. Add a new student record
def addStudent():
global df
student_id = int(input("Enter Student ID: "))
name = input("Enter Student Name: ")
subject = input("Enter Subject: ")
marks = int(input("Enter Marks: "))
new_data = pd.DataFrame([[student_id, name, subject, marks]],
columns=["Student ID", "Name", "Subject", "Marks"])
df = pd.concat([df, new_data], ignore_index=True)
print("New student record added successfully!")

Output >>
OPTION 2
Program >>>
# 2. Update an existing student record
def updateStudent():
global df
student_id = int(input("Enter Student ID to update: "))
if student_id in df["Student ID"].values:
name = input("Enter new Student Name (leave blank to keep existing): ")
subject = input("Enter new Subject (leave blank to keep existing): ")
marks = input("Enter new Marks (leave blank to keep existing): ")
if name:
df.loc[df["Student ID"] == student_id, "Name"] = name
if subject:
df.loc[df["Student ID"] == student_id, "Subject"] = subject
if marks:
df.loc[df["Student ID"] == student_id, "Marks"] = int(marks)
print("Student record updated successfully!")
else:
print("Student ID not found.")
Output >>
OPTION 3
Program >>>
# 3. View all student records
def viewAllRecords():
print("\nAll Student Records:")
print(df)
Output >>
OPTION 4
Program >>>
# 4. Search for a student by ID
def searchStudentByID():
student_id = int(input("Enter Student ID to search: "))
record = df[df["Student ID"] == student_id]
if not record.empty:
print("Student Record Found:")
print(record)
else:
print("No record found with the given Student ID.")

Output >>
OPTION 5
Program >>>
# 5. Search for students by subject
def searchBySubject():
subject = input("Enter Subject to search: ")
records = df[df["Subject"].str.lower() == subject.lower()]
if not records.empty:
print("Records Found:")
print(records)
else:
print("No records found for the given subject.")

Output >>
OPTION 6
Program >>>
# 6. Delete a student record
def deleteStudent():
global df
student_id = int(input("Enter Student ID to delete: "))
if student_id in df["Student ID"].values:
df = df[df["Student ID"] != student_id]
print("Record deleted successfully!")
else:
print("Student ID not found.")
Output >>
OPTION 7
Program >>>
# 7. Calculate average marks for a subject
def averageMarksBySubject():
subject = input("Enter Subject to calculate average marks: ")
avg_marks = df[df["Subject"].str.lower() == subject.lower()]["Marks"].mean()
if not pd.isna(avg_marks):
print(f"Average Marks for {subject}: {avg_marks:.2f}")
else:
print("No data available for the given subject.")

Output >>
OPTION 8
Program >>>
# 8. Find the highest scorer in a subject
def highestScorerBySubject():
subject = input("Enter Subject to find the highest scorer: ")
records = df[df["Subject"].str.lower() == subject.lower()]
if not records.empty:
top_scorer = records.loc[records["Marks"].idxmax()]
print(f"Highest Scorer in {subject}:")
print(top_scorer)
else:
print("No data available for the given subject.")
Output >>
OPTION 9
Program >>>

# 9. Count total students in a subject


def countStudentsBySubject():
subject = input("Enter Subject: ")
count = df[df["Subject"].str.lower() == subject.lower()].shape[0]
print(f"Total students in {subject}: {count}")
Output >>
OPTION 10
Program >>>

# 10. Display data for students scoring above a threshold


def studentsAboveThreshold():
threshold = int(input("Enter marks threshold: "))
records = df[df["Marks"] > threshold]
if not records.empty:
print("Students scoring above threshold:")
print(records)
else:
print("No students found with marks above the given threshold.")

Output >>
OPTION 11
Program >>>
# 11. Save data for a specific subject to a CSV file
def saveSubjectData():
subject = input("Enter Subject: ")
records = df[df["Subject"].str.lower() == subject.lower()]
if not records.empty:
filename = f"{subject}_data.csv"
records.to_csv(filename, index=False)
print(f"Data for {subject} saved to {filename}.")
else:
print("No data found for the given subject.")

Output >>
OPTION 12
Program >>>
# 12. Export entire data to CSV
def exportToCSV():
global df
df.to_csv("ExamData.csv", index=False)
print("Data saved to ExamData.csv.")

Output >>
OPTION 13
Program >>>
# 13. Bar chart of marks by student
def barChartMarks():
df.plot(x="Name", y="Marks", kind="bar", title="Marks Bar Chart", color="navy")
plt.xlabel("Student Name")
plt.ylabel("Marks")
plt.xticks(rotation=45)
plt.show()

Output >>
OPTION 14
Program >>>
# 14. Line graph of student marks
def lineGraphMarks():
df.sort_values("Marks", inplace=True)
plt.plot(df["Name"], df["Marks"], marker="o", linestyle="-", color="green", label="Marks")
plt.title("Student Marks Line Graph")
plt.xlabel("Student Name")
plt.ylabel("Marks")
plt.xticks(rotation=45)
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
Output >>
OPTION 15
Program >>>
# 15. Combined bar graph for subject averages and highest marks

def combinedBarGraph():
avg_marks = df.groupby("Subject")["Marks"].mean()
highest_marks = df.groupby("Subject")["Marks"].max()
x = avg_marks.index
x_labels = range(len(x))
plt.bar(x_labels, avg_marks, width=0.4, label="Average Marks", color="lightblue",
align="center")
plt.bar([p + 0.4 for p in x_labels], highest_marks, width=0.4, label="Highest Marks",
color="orange")
plt.xticks([p + 0.2 for p in x_labels], x, rotation=45)
plt.xlabel("Subjects")
plt.ylabel("Marks")
plt.title("Subject-wise Average and Highest Marks")
plt.legend()
plt.tight_layout()
plt.show()
Output >>
OPTION 16
Program >>>
# 16. Histogram of marks distribution
def histogramMarks():
df["Marks"].plot(kind="hist", bins=5, title="Marks Distribution", color="orange")
plt.xlabel("Marks")
plt.ylabel("Frequency")
plt.show()

Output >>
OPTION 17
Program >>>

# 17. Save data to PDF report


def saveToPDF():
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size=12)
pdf.cell(200, 10, txt="Exam Marks Report", ln=True, align="C")
for i in range(len(df)):
record = df.iloc[i]
pdf.cell(200, 10, txt=f"{record.to_dict()}", ln=True)
pdf.output("ExamReport.pdf")
print("Data saved to ExamReport.pdf.")

Output >>
OPTION 18
Program >>>
elif choice == 18:
print("Exiting...")
break

Output >>
CSV
BIBLIOGRAPHY

www.google.com
www.wikipedia.con
www.python.org/help
NCERT Informatics Practices (2024-25)
CLASS XII

You might also like