Skip to content
Activities · Activity 3.1

Q.Write the python statements to print the sum of the english marks scored by Mishti.
[Table: The chapter's case study (Program 3.1) stores unit test marks of 4 students (maximum marks 25 in each subject) in a DataFrame df created from the dictionary marksUT = {'Name':['Raman','Raman','Raman','Zuhaire','Zuhaire','Zuhaire','Ashravy','Ashravy','Ashravy','Mishti','Mishti','Mishti'], 'UT':[1,2,3,1,2,3,1,2,3,1,2,3], 'Maths':[22,21,14,20,23,22,23,24,12,15,18,17], 'Science':[21,20,19,17,15,18,19,22,25,22,21,18], 'S.St':[18,17,15,22,21,19,20,24,19,25,25,20], 'Hindi':[20,22,24,24,25,23,15,17,21,22,24,25], 'Eng':[21,24,23,19,15,13,22,21,23,22,23,20]}.]

Punjab PsebTextbookSubjective· 2mImportance★★★★★
6% · 3/53 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Filter the case-study DataFrame df down to Mishti's three rows with a boolean mask (df['Name'] == 'Mishti'), pick out the Eng column, and call .sum() on it. Mishti's three English scores (22, 23, 20) add up to 65.

The case-study DataFrame df (built in Program 3-1 from the marksUT dictionary) stores 12 rows -- one row per student per Unit Test. To get a single student's total in one subject, we need two operations chained together: first filter the rows down to that student, then aggregate one column of the filtered result.

import pandas as pd

marksUT = {
    'Name': ['Raman', 'Raman', 'Raman', 'Zuhaire', 'Zuhaire', 'Zuhaire',
              'Ashravy', 'Ashravy', 'Ashravy', 'Mishti', 'Mishti', 'Mishti'],
    'UT': [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],
    'Maths': [22, 21, 14, 20, 23, 22, 23, 24, 12, 15, 18, 17],
    'Science': [21, 20, 19, 17, 15, 18, 19, 22, 25, 22, 21, 18],
    'S.St': [18, 17, 15, 22, 21, 19, 20, 24, 19, 25, 25, 20],
    'Hindi': [20, 22, 24, 24, 25, 23, 15, 17, 21, 22, 24, 25],
    'Eng': [21, 24, 23, 19, 15, 13, 22, 21, 23, 22, 23, 20]
}
df = pd.DataFrame(marksUT)

Step 1 -- filter to Mishti's rows. The same pattern the textbook itself uses (Program 3-3, filtering to Mishti to find her minimum marks): compare the Name column to 'Mishti', which produces a Boolean Series the same length as df -- True for the three rows belonging to Mishti (index 9, 10, 11), False for the other nine:

mask = df['Name'] == 'Mishti'
print(mask)

Output:

0     False
1     False
2     False
3     False
4     False
5     False
6     False
7     False
8     False
9      True
10     True
11     True
Name: Name, dtype: bool

Passing that mask back into df[...] keeps only the rows where it is True:

dfMishti = df[df['Name'] == 'Mishti']
print(dfMishti)

Output:

    Name  UT  Maths  Science  S.St  Hindi  Eng
9   Mishti   1     15       22    25     22   22
10  Mishti   2     18       21    25     24   23
11  Mishti   3     17       18    20     25   20

Step 2 -- select the Eng column and sum it. From dfMishti, ['Eng'] picks a single Series of three values, and .sum() adds them:

sum_english_marks_mishti = dfMishti['Eng'].sum()
print(f"The sum of English marks scored by Mishti is: {sum_english_marks_mishti}")

Output:

The sum of English marks scored by Mishti is: 65
``` …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.