Question:

What will be the output of the command df.count(axis = 1)?

Show Hint

axis=1 works across columns for each row, and count() counts non-NaN values.
Updated On: Oct 1, 2026
  • The total number of row in a dataframe.
  • The total number of values in each row.
  • The total number of columns in each dataframe
  • The total number of NaN values in each row
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: Understanding the Concept:
The method df.count() counts the non-NaN (non-missing) values. The axis argument tells pandas the direction. axis=0 goes down the rows and gives one count for each column. axis=1 goes across the columns and gives one count for each row.

Step 2: Try a small example.
Take a DataFrame with columns a and b, where a = 1, NaN, 3 and b = 4, 5, NaN. Running df.count(axis=1) gives 2, 1, 1. That is one number for each row, and it counts only the real values. I ran this in Python to confirm.

Step 3: Check option 1.
The total number of rows in a DataFrame is given by len(df) or df.shape[0]. The result of count is a Series with one entry per row, not a single number. So option 1 is wrong.

Step 4: Check option 2.
The output has one count for each row, and that count is the number of values present in that row. So option 2 is correct.

Step 5: Check option 3.
The number of columns is given by df.shape[1]. count does not report this, and it gives one count per row, not per DataFrame. So option 3 is wrong.

Step 6: Check option 4.
count ignores NaN values. It counts the opposite, the values that are not NaN. The NaN count would be df.isnull().sum(axis=1). So option 4 is wrong.

Step 7: Final Answer:
df.count(axis=1) gives the number of values in each row, which is option 2. \[ \boxed{\text{The total number of values in each row}} \]
Was this answer helpful?
0
0