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.


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


Parameters axis, level and numeric_only are unsupported.


Count non-NA cells for each column or row.
import pandas as pd
import numpy as np
from numba import 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()

$ python ./dataframe/
A    4
B    4
C    3
dtype: int64

See also


Number of non-NA elements in a Series.


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


Boolean same-sized DataFrame showing places of NA elements.