English

Try to write a short code to get the above output. Remember to print the relevant headings of the output. Slicing of the DataFrame to get only the marks

Advertisements
Advertisements

Question

Try to write a short code to get the above output. Remember to print the relevant headings of the output.

Slicing of the DataFrame to get only the marks

  Maths Science S.St Hindi Eng
3 20 17 22 24 19
4 23 15 21 25 15
5 22 18 19 23 13

Average of marks obtained by Zuhaire in all Unit Tests

3 20.4
4 19.8
5 19.0
dtype float64
Code Writing
Advertisements

Solution

import pandas as pd
df = pd.DataFrame
(
     {
    'Name': ['Zuhaire','Zuhaire','Zuhaire'],
    'UT': [1,2,3],
    'Maths': [20,23,22],
    'Science': [17,15,18],
    'S.St': [22,21,19],
    'Hindi': [24,25,23],
    'Eng': [19,15,13]
     }
)
dfZuhaire = df[df['Name'] == 'Zuhaire']
print("Slicing of the DataFrame to get only the marks")
print(dfZuhaire[['Maths','Science','S.St','Hindi','Eng']])
print("\nAverage of marks obtained by Zuhaire in all Unit Tests")
print(dfZuhaire[['Maths','Science','S.St','Hindi','Eng']].mean(axis=1))
shaalaa.com
  Is there an error in this question or solution?
Chapter 3: Data Handling using Pandas - II - Intext Questions [Page 71]

APPEARS IN

NCERT Informatics Practices [English] Class 12
Chapter 3 Data Handling using Pandas - II
Intext Questions | Q 3. | Page 71
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×