0% found this document useful (0 votes)
2 views

output project

The document describes a Python script that collects student data including admission number, name, date of birth, class, and marks in various subjects. It creates a DataFrame to store this data, calculates the total marks and percentage, saves the DataFrame to a CSV file, and visualizes the percentage of marks in a bar graph. The script allows for the dynamic addition of student records until the user decides to stop.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

output project

The document describes a Python script that collects student data including admission number, name, date of birth, class, and marks in various subjects. It creates a DataFrame to store this data, calculates the total marks and percentage, saves the DataFrame to a CSV file, and visualizes the percentage of marks in a bar graph. The script allows for the dynamic addition of student records until the user decides to stop.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import pandas as pd

import matplotlib.pyplot as plt

# Initialize DataFrame with predefined columns


cols = ['admn', 'name', 'dob', 'class', 'maths', 'english', 'science', 'marks',
'percentage']
df = pd.DataFrame([], columns=cols)

# Create DataFrame
print("Enter student data:")
data = []
while True:
add_row = input("Add a new student? (y/n): ").lower()
if add_row == 'y':
admn = int(input("Admission Number: "))
name = input("Student Name: ")
dob = input("DOB (dd-mm-yyyy): ")
std = int(input("Class: "))
maths = float(input("Maths Marks (out of 100): "))
english = float(input("English Marks (out of 100): "))
science = float(input("Science Marks (out of 100): "))
marks = maths + english + science
percentage = (marks / 300) * 100 # Calculate percentage
data.append([admn, name, dob, std, maths, english, science, marks,
percentage])
else:
break

df = pd.DataFrame(data, columns=cols)
print("\nDataFrame Created Successfully:")
print(df)

# Automatically save DataFrame to CSV


file_name = "data_students.csv"
df.to_csv(file_name, index=False)
print(f"\nDataFrame saved to '{file_name}'.")

# Automatically visualize data in bar graph


print("\nVisualizing Data (Percentage)...")
plt.bar(df['name'], df['percentage'], color='skyblue')
plt.xlabel("Students")
plt.ylabel("Percentage")
plt.title("Percentage of Marks by Students")
plt.ylim(0, 100) # Set Y-axis to max 100%
plt.show()

output

Enter student data:


Add a new student? (y/n): y
Admission Number: 123
Student Name: jahnvi
DOB (dd-mm-yyyy): 28-09-2007
Class: 12
Maths Marks (out of 100): 98
English Marks (out of 100): 99
Science Marks (out of 100): 95
Add a new student? (y/n): y
Admission Number: 124
Student Name: jeevansh
DOB (dd-mm-yyyy): 06-09-2007
Class: 12
Maths Marks (out of 100): 90
English Marks (out of 100): 89
Science Marks (out of 100): 88
Add a new student? (y/n): y
Admission Number: 125
Student Name: shivam
DOB (dd-mm-yyyy): 12-12-2007
Class: 12
Maths Marks (out of 100): 88
English Marks (out of 100): 87
Science Marks (out of 100): 89
Add a new student? (y/n): n

DataFrame Created Successfully:


admn name dob class ... english science marks percentage
0 123 jahnvi 28-09-2007 12 ... 99.0 95.0 292.0 97.333333
1 124 jeevansh 06-09-2007 12 ... 89.0 88.0 267.0 89.000000
2 125 shivam 12-12-2007 12 ... 87.0 89.0 264.0 88.000000

[3 rows x 9 columns]

DataFrame saved to 'data_students.csv'.

Visualizing Data (Percentage)...

You might also like