0% found this document useful (0 votes)
11 views8 pages

Project 4

The Student Marks Management and Analysis System generates marks for 100 students across 5 subjects, stores the data in a MySQL database, and calculates total and average marks using Pandas. It visualizes the top performers with Matplotlib. The project includes SQL setup, Python code for data generation and analysis, and instructions for running the project.

Uploaded by

eswarannihil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views8 pages

Project 4

The Student Marks Management and Analysis System generates marks for 100 students across 5 subjects, stores the data in a MySQL database, and calculates total and average marks using Pandas. It visualizes the top performers with Matplotlib. The project includes SQL setup, Python code for data generation and analysis, and instructions for running the project.

Uploaded by

eswarannihil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Project: Student Marks Management and

Analysis System

📝 Project Description:
This project:
 Generates marks for 100 students in 5
subjects
 Stores the data in a MySQL database
 Calculates total and average marks using
Pandas
 Visualizes top performers using Matplotlib
1. MySQL Table Setup

CREATE DATABASE IF NOT EXISTS student_db;

USE student_db;

CREATE TABLE IF NOT EXISTS student_marks (


student_id INT PRIMARY KEY,
student_name VARCHAR(50),
math INT,
physics INT,
chemistry INT,
biology INT,
english INT
);
2. Python Code (student_analysis.py)

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import mysql.connector

# 1. Generate fake student data


np.random.seed(123)
student_ids = np.arange(1, 101)
student_names = [f"Student_{i}" for i in
student_ids]
math = np.random.randint(40, 100, size=100)
physics = np.random.randint(40, 100, size=100)
chemistry = np.random.randint(40, 100, size=100)
biology = np.random.randint(40, 100, size=100)
english = np.random.randint(40, 100, size=100)
# 2. Create DataFrame
df = pd.DataFrame({
'student_id': student_ids,
'student_name': student_names,
'math': math,
'physics': physics,
'chemistry': chemistry,
'biology': biology,
'english': english
})

# 3. Save to MySQL
try:
conn = mysql.connector.connect(
host="localhost",
user="root",
password="your_password", # Replace this
database="student_db"
)
cursor = conn.cursor()

cursor.execute("DELETE FROM student_marks")


conn.commit()

for _, row in df.iterrows():


cursor.execute("""
INSERT INTO student_marks (student_id,
student_name, math, physics, chemistry, biology,
english)
VALUES (%s, %s, %s, %s, %s, %s, %s)
""", (
int(row['student_id']),
row['student_name'],
int(row['math']),
int(row['physics']),
int(row['chemistry']),
int(row['biology']),
int(row['english'])
))
conn.commit()
print("✅ Student marks inserted into MySQL!")

except mysql.connector.Error as err:


print("❌ MySQL Error:", err)

finally:
if conn.is_connected():
cursor.close()
conn.close()

# 4. Analyze total and average marks


df['total'] = df[['math', 'physics', 'chemistry',
'biology', 'english']].sum(axis=1)
df['average'] = df['total'] / 5
top10 = df.sort_values(by='total',
ascending=False).head(10)
print("\n📊 Top 10 Students by Total Marks:")
print(top10[['student_name', 'total', 'average']])

# 5. Plot
plt.figure(figsize=(12, 6))
plt.bar(top10['student_name'], top10['total'],
color='limegreen')
plt.xticks(rotation=45)
plt.title("Top 10 Students by Total Marks")
plt.xlabel("Student")
plt.ylabel("Total Marks")
plt.tight_layout()
plt.show()

3. Install Required Libraries


pip install numpy pandas matplotlib mysql-
connector-python

4. Run the Project


1.Run the SQL queries to set up the database
and table.
2.Replace your_password in the Python
script.
3.Run the script:
python student_analysis.py

You might also like