CBSE Class 12 Informatics Practices Question 23 of 44

Data Handling using Pandas — Question 24

Back to all questions
24
Question

Question 21

Write a program that reads students marks from a ‘Result.csv’ file and displays percentage of each student.

Solution
import pandas as pd
df = pd.read_csv('Result.csv')
df['Total_marks'] = df[['Maths', 'Science', 'English',]].sum(axis=1)
df['Percentage'] = (df['Total_marks'] / 300) * 100
print("Percentage of each student: ")
print(df[['Name', 'Percentage']])
Output
Percentage of each student: 
    Name  Percentage
0  Rahul   85.000000
1  Rohan   81.666667
2   Riya   88.333333
3    Raj   86.666667
Answer

import
pandas
as
pd
df
=
pd
.
read_csv
(
'Result.csv'
)
df
[
'Total_marks'
]
=
df
[[
'Maths'
,
'Science'
,
'English'
,]].
sum
(
axis
=
1
)
df
[
'Percentage'
]
=
(
df
[
'Total_marks'
]
/
300
)
*
100
print
(
"Percentage of each student: "
)
print
(
df
[[
'Name'
,
'Percentage'
]])
Output
Percentage of each student:
Name Percentage
0 Rahul 85.000000
1 Rohan 81.666667
2 Riya 88.333333
3 Raj 86.666667