Question:medium

Consider the given DataFrame df4:

NAMEPERIODICENGMATHSSCIENCE
MEENA1406080
REENA2603010
TEENA3806040
SHEENA2902070

We want the following output:

NAMEMEENAREENATEENASHEENA
PERIODIC8
ENG270
MATHS170
SCIENCE200

Show Hint

Use \texttt{numeric__only=False} to include string concatenation along with numeric summation in Pandas.
Updated On: Feb 16, 2026
  • print(df4.sum(numeric_only=True))
  • print(df4.sum(numeric_only=False))
  • print(df4.sum())
  • print(df4.count(numeric_only=True))
Show Solution

The Correct Option is B

Solution and Explanation

Step 1: Behavior of sum()
- `sum()` aggregates numeric values within each column.
- Setting `numeric__only=True` restricts the operation to numeric columns only.
- Setting `numeric__only=False` includes both numeric and string columns.

Step 2: String Concatenation
The "NAME" column, being of string type, will have its values concatenated when included in `sum()`:
\[\text{Name column} = "MEENAREENATEENASHEENA"\]
Step 3: Numeric Column Aggregations
- PERIODIC: \(1+2+3+2=8\)
- ENG: \(40+60+80+90=270\)
- MATHS: \(60+30+60+20=170\)
- SCIENCE: \(80+10+40+70=200\)
\[\boxed{\text{Correct Output obtained only with numeric__only=False}}\]
Was this answer helpful?
0


Questions Asked in CUET (UG) exam