What will be the output of the command df.count(axis = 1)?
What will be the output of the command df.count(axis = 1)?
Solution
In pandas, df.count(axis = 1) goes across the columns and returns one number for each row. That number is how many values the row holds, and cells with NaN are not counted. With axis = 0 (the default), it gives the count for each column instead.
Option 1: the number of rows in a dataframe comes from len(df) or df.shape[0], not from count().
Option 3: count() returns a count for every row, not for each dataframe, and the number of columns comes from df.shape[1].
Option 4: this is the opposite of what count() does, since it skips NaN values. NaN counts per row come from df.isnull().sum(axis = 1).
Related questions:
2026: 19 May Shift 1
2026: 21 May Shift 1
2025: 13 May Shift 2