How to count dataframe values () | pandas.DataFrame.count() function
pandas.DataFrame.count(): This function returns for each column/row the number of non-NA/null entries. If level is specified returns a DataFrame.
Syntax: DataFrame.count(axis=0, level=None, numeric_only=False):
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.
Parameters:
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.
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.
numeric_only : boolean, default False
Include only float, int or boolean data.
Returns:
Series or DataFrame
For each column/row the number of non-NA/null entries. If level is specified returns a DataFrame.
pandas.DataFrame.count() function example program
import numpy as np
import pandas as pd
df = pd.DataFrame({'A': [5, 2], 'B': [4, 8], 'C':[9,10]})
print(df.count())
Output:
A 2 B 2 C 2 dtype: int64