Skip to content
Programs · Program 3-1

Q.Store the Result data in a DataFrame called marksUT.
(Create the DataFrame from the case-study marks of the four students — Raman, Zuhaire, Ashravy and Mishti — across Unit Tests 1, 2 and 3 in the subjects Maths, Science, S.St, Hindi and Eng.)

Rajasthan RbseTextbookSubjective· 3mImportance★★★★★
2% · 1/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 →

Build the case-study DataFrame marksUT (and its printable form df) straight from the REAL marks given in Table 3.1 of the chapter — the four students' Maths, Science, S.St, Hindi and Eng scores across Unit Tests 1-3 — using one dictionary of equal-length lists.

Why a dictionary-of-lists is the right constructor here

pd.DataFrame() accepts many input shapes, but when your source data is already organised as "one list of values per column," a dictionary of lists is the most direct fit: each key becomes a column name, each value (a list) becomes that column's data, top to bottom. Pandas aligns the lists by position — the 1st value in every list belongs to row 0, the 2nd value in every list belongs to row 1, and so on. So before writing any code, the real design question is: what does each row represent?

Here, each row must represent one student's marks in one unit test — not one student overall. Since there are 4 students × 3 unit tests, that's 12 rows, and each of the 7 lists (Name, UT, Maths, Science, S.St, Hindi, Eng) must therefore hold exactly 12 values, kept in the same student/test order throughout.

The real data (Table 3.1)

NameUTMathsScienceS.StHindiEng
Raman12221182021
Raman22120172224
Raman31419152423
Zuhaire12017222419
Zuhaire22315212515
Zuhaire32218192313
Ashravy12319201522
Ashravy22422241721
Ashravy31225192123
Mishti11522252222
Mishti21821252423
Mishti31718202520
Tip

The chapter's own intro table spells the third student's name "Aashravy," but every piece of actual code and every printed output in the chapter uses "Ashravy" (one A). That's the textbook's own inconsistency between its prose and its code — always follow the code/output spelling, since that is what every later program (max, min, sort, groupby, ...) filters and matches on.

The code

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)
print(df)

Output:

       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
3   Zuhaire   1     20       17    22     24   19
4   Zuhaire   2     23       15    21     25   15
5   Zuhaire   3     22       18    19     23   13
6   Ashravy   1     23       19    20     15   22 …

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.