94
Pandas DataFrame.count()
The Pandas count() is defined as a method that is used to count the number of non-NA cells for each column or row. It is also suitable to work with the non-floating data.
Syntax:
Parameters:
- axis: {0 or ‘index’, 1 or ‘columns’}, default value 0
0 or ‘index’ is used for row-wise, whereas 1 or ‘columns’ is used for column-wise. - level: int or str
It is an optional parameter. If an axis is hierarchical, it counts along with the particular level and collapsing into the DataFrame. - numeric_only: bool, default value False
It only includes int, float, or Boolean data.
Returns:
It returns the count of Series or DataFrame if the level is specified.
Example 1: The below example demonstrates the working of the count().
Output
Person 5 Age 3 dtype: int64
Example 2: If we want to count for each of the row, we can use the axis parameter. The below code demonstrates the working of the axis parameter.
Output
0 2 1 2 2 1 3 2 dtype: int64
Next TopicDataFrame.cut()