हिंदी

Can you write a shortened code to get the output of the program? Name Raman Raman Raman UT 1 2 3 Maths 22 21 14 Maths 22 21 14 S.St 18 17 15

Advertisements
Advertisements

प्रश्न

Can you write a shortened code to get the output of the program?

  Name UT Maths Science S.St Hindi Eng
0 Raman 1 22 21 18 20 21
1 Raman 2 21 20 17 22 24
2 Raman 3 14 19 15 24 23

>>> dfRaman[['Maths','Science','S. St','Hindi','Eng']].sum()

Maths 57
Science 60
S.St 50
Hindi 66
Eng 68
dtype int64

>>> dfRaman[['Maths','Science','S. St','Hindi','Eng']].sum(axis=1)

0 102
1 104
2 95
dtype int64
कोड लेखन
Advertisements

उत्तर

import pandas as pd
df = pd.DataFrame({
    'Name':['Raman','Raman','Raman'],
    'UT':[1,2,3],
    'Maths':[22,21,14],
    'Science':[21,20,19],
    'S.St':[18,17,15],
    'Hindi':[20,22,24],
    'Eng':[21,24,23]
})
dfRaman = df[df['Name']=='Raman']
print("Marks obtained by Raman in each test are:")
print(dfRaman)
print("\nTotal marks obtained by Raman in each subject:")
print(dfRaman[['Maths','Science','S.St','Hindi','Eng']].sum())
print("\nTotal marks scored by Raman in each test:")
print(dfRaman[['Maths','Science','S.St','Hindi','Eng']].sum(axis=1))
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 3: Data Handling using Pandas - II - Intext Questions [पृष्ठ ६९]

APPEARS IN

एनसीईआरटी Informatics Practices [English] Class 12
अध्याय 3 Data Handling using Pandas - II
Intext Questions | Q 1. | पृष्ठ ६९
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×