- API reference
- DataFrame
- pandas.DataF...
pandas.DataFrame.count#
- DataFrame.count(axis=0,numeric_only=False)[source]#
Count non-NA cells for each column or row.
The valuesNone,NaN,NaT,
pandas.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.
- numeric_onlybool, default False
Include onlyfloat,int orboolean data.
- Returns:
- Series
For each column/row the number of non-NA/null entries.
See also
Series.count
Number of non-NA elements in a Series.
DataFrame.value_counts
Count unique combinations of columns.
DataFrame.shape
Number of DataFrame rows and columns (including NA elements).
DataFrame.isna
Boolean same-sized DataFrame showing places of NA elements.
Examples
Constructing DataFrame from a dictionary:
>>>df=pd.DataFrame({"Person":...["John","Myla","Lewis","John","Myla"],..."Age":[24.,np.nan,21.,33,26],..."Single":[False,True,True,True,False]})>>>df Person Age Single0 John 24.0 False1 Myla NaN True2 Lewis 21.0 True3 John 33.0 True4 Myla 26.0 False
Notice the uncounted NA values:
>>>df.count()Person 5Age 4Single 5dtype: int64
Counts for eachrow:
>>>df.count(axis='columns')0 31 22 33 34 3dtype: int64
On this page