pandas.DataFrame.count

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.

param axis
{0 or ‘index’, 1 or ‘columns’}, default 0

If 0 or ‘index’ counts are generated for each column. If 1 or ‘columns’ counts are generated for each row.

param level
int or str, optional

If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a DataFrame. A str specifies the level name.

param numeric_only
bool, default False

Include only float, int or boolean data.

return

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

Limitations

Parameters axis, level and numeric_only are unsupported.

Examples

Count non-NA cells for each column or row.
import pandas as pd
import numpy as np
from numba import njit


@njit
def dataframe_count():
    df = pd.DataFrame({"A": [.2, .0, .6, .2],
                       "B": [2, 0, 6, 2],
                       "C": [-1, np.nan, 1, np.inf]})

    return df.count()


print(dataframe_count())
$ python ./dataframe/dataframe_count.py
A    4
B    4
C    3
dtype: int64

See also

Series.count

Number of non-NA elements in a Series.

DataFrame.shape

Number of DataFrame rows and columns (including NA elements).

DataFrame.isna

Boolean same-sized DataFrame showing places of NA elements.