KnowledgeBoat Logo
|

Informatics Practices

Consider the following Class12.csv file containing the data as given below:

RollNoNameAccountsMathsBStIPEco
10Ritu Jain8867879756
11Mridul Mehta6778778790
12Divij8789788292
13Yashvi Verma6782.376.598.278.6
14Deepak Virmani56.776.5887867
15Jatin Malik76667787.567.5

(a) Read the csv file into a dataframe df which is stored with tab ('\t') separator.

(b) Write the code to find the total marks (Total_ marks) for each student and add it to the newly-created dataframe.

(c) Also calculate the percentage obtained by each student under a new column “Average” in the dataframe.

Python Data Handling

7 Likes

Answer

(a)

df = pd.read_csv('Class12.csv', sep='\t')
Output
   RollNo            Name  Accounts  Maths   BSt    IP   Eco
0      10       Ritu Jain      88.0   67.0  87.0  97.0  56.0
1      11    Mridul Mehta      67.0   78.0  77.0  87.0  90.0
2      12           Divij      87.0   89.0  78.0  82.0  92.0
3      13    Yashvi Verma      67.0   82.3  76.5  98.2  78.6
4      14  Deepak Virmani      56.7   76.5  88.0  78.0  67.0
5      15     Jatin Malik      76.0   66.0  77.0  87.5  67.5

(b)

df['Total_marks'] = df[['Accounts', 'Maths', 'BSt', 'IP', 'Eco']].sum(axis=1)
Output
   RollNo            Name  Accounts  Maths   BSt    IP   Eco  Total_marks
0      10       Ritu Jain      88.0   67.0  87.0  97.0  56.0        395.0
1      11    Mridul Mehta      67.0   78.0  77.0  87.0  90.0        399.0
2      12           Divij      87.0   89.0  78.0  82.0  92.0        428.0
3      13    Yashvi Verma      67.0   82.3  76.5  98.2  78.6        402.6
4      14  Deepak Virmani      56.7   76.5  88.0  78.0  67.0        366.2
5      15     Jatin Malik      76.0   66.0  77.0  87.5  67.5        374.0

(c)

df['Average'] = (df['Total_marks'] / 500) * 100
Output
   RollNo            Name  Accounts  Maths   BSt    IP   Eco  Total_marks  Average
0      10       Ritu Jain      88.0   67.0  87.0  97.0  56.0        395.0    79.00
1      11    Mridul Mehta      67.0   78.0  77.0  87.0  90.0        399.0    79.80
2      12           Divij      87.0   89.0  78.0  82.0  92.0        428.0    85.60
3      13    Yashvi Verma      67.0   82.3  76.5  98.2  78.6        402.6    80.52
4      14  Deepak Virmani      56.7   76.5  88.0  78.0  67.0        366.2    73.24
5      15     Jatin Malik      76.0   66.0  77.0  87.5  67.5        374.0    74.80

Answered By

3 Likes


Related Questions