Question:

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: Sep 18, 2025
  • print(df4.sum(numeric_only=True))
  • print(df4.sum(numeric_only=False))
  • print(df4.sum())
  • print(df4.count(numeric_only=True))
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: Behavior of sum()
- \texttt{sum()} adds up numeric values in each column.
- With \texttt{numeric__only=True}, only numeric columns are included.
- With \texttt{numeric__only=False}, both numeric and string columns are processed.

Step 2: String concatenation
The column "NAME" is of string type. When included in sum(), all names are concatenated:
\[ \text{Name column} = "MEENAREENATEENASHEENA" \]
Step 3: Numeric column sums
- 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
0

Questions Asked in CUET exam

View More Questions