Q.Write the statement to display the first and third quartiles of all subjects.
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 →DataFrame.quantile() defaults to the 0.5 quantile (the median). Passing a list of fractions — [.25, .75] — instead of one at a time returns both the first quartile (25th percentile) and third quartile (75th percentile) together, as a two-row result.
What a "quantile" is, briefly
A quantile cuts the sorted data at a given fraction: q=0.25 (the first quartile, Q1) is the value below which 25% of the data falls; q=0.75 (the third quartile, Q3) is the value below which 75% falls. q=0.5 is the median — the same value DataFrame.median() returns. In fact, calling df.quantile() with no argument at all defaults to q=0.5.
The book's own two-step version (over the WHOLE df)
Before this program, the chapter shows .quantile() used one fraction at a time, over every numeric column including UT:
print(df.quantile(q=.25))
UT 1.00
Maths 16.50
Science 18.00
S.St 18.75
Hindi 20.75
Eng 19.75
Name: 0.25, dtype: float64
print(df.quantile(q=.75))
UT 3.00
Maths 22.25
Science 21.25
S.St 22.50
Hindi 24.00
Eng 23.00
Name: 0.75, dtype: float64
Two separate calls, two separate results — and a UT quartile that isn't actually meaningful (UT is a test number, 1/2/3, not a mark).
This program's version — subjects only, in one call
Since the question specifically asks for the quartiles "of all subjects" (not of UT), select just the five subject columns first, then request both quantiles in a single call by passing a list:
dfSubject = df[['Maths','Science','S.St','Hindi','Eng']]
dfQ = dfSubject.quantile([.25, .75])
print(dfQ)
Output:
Maths Science S.St Hindi Eng
0.25 16.50 18.00 18.75 20.75 19.75
0.75 22.25 21.25 22.50 24.00 23.00
``` …
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.