w3resource

Pandas DataFrame: count() function

DataFrame - count() function

The count() function is used to count non-NA cells for each column or row.

The values None, NaN, NaT, and optionally numpy.inf (depending on pandas.options.mode.use_inf_as_na) are considered NA.

Syntax:

DataFrame.count(self, axis=0, level=None, numeric_only=False)

Parameters:

Name Description Type/Default Value Required / Optional
axis       If 0 or ‘index’ counts are generated for each column. If 1 or ‘columns’ counts are generated for each row {0 or ‘index’, 1 or ‘columns’}
Default Value: 0
Required
level      If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a DataFrame. A str specifies the level name. int or str Optional
numeric_only  Include only float, int or boolean data. bool
Default Value: False
 

Returns: Series or DataFrame
For each column/row the number of non-NA/null entries. If level is specified returns a DataFrame.

Example:


Download the Pandas DataFrame Notebooks from here.

Previous: DataFrame - corr() function
Next: DataFrame - cov() function



Follow us on Facebook and Twitter for latest update.