Skip to content
Programs · Program 3-5

Q.Write a statement to count the number of values in a row.

Tamil Nadu DgeTextbookSubjective· 2mImportance★★★★★
19% · 10/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 →

DataFrame.count() counts non-null values; the direction it counts in flips with axis — axis=0 (the default) counts DOWN each column, axis=1 counts ACROSS each row. At this point in the chapter df has no missing values yet, so both directions currently return a "clean" flat number.

The default direction — down each column

print(df.count())

Output:

Name       12
UT         12
Maths      12
Science    12
S.St       12
Hindi      12
Eng        12
dtype: int64

Every column reports 12 — unsurprising, since the case-study df has 12 rows and (at this point in the chapter) no missing data at all. This is count()'s default behaviour (axis=0): for each column, count how many of its 12 cells actually hold a value.

What Program 3-5 asks for — across each row instead

print(df.count(axis=1))

Output:

0     7
1     7
2     7
3     7
4     7
5     7
6     7
7     7
8     7
9     7
10    7
11    7
dtype: int64

Passing axis=1 flips the direction: for each row, count how many of its columns have a value. Every row has exactly 7 fields (Name, UT, Maths, Science, S.St, Hindi, Eng), and every one of them is filled in, so every row reports 7.

Why this matters beyond a "no missing data" flex …

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.