@@ -5851,22 +5851,78 @@ def corrwith(self, other, axis=0, drop=False):
5851
5851
5852
5852
def count (self , axis = 0 , level = None , numeric_only = False ):
5853
5853
"""
5854
- Return Series with number of non-NA/null observations over requested
5855
- axis. Works with non-floating point data as well (detects NaN and None)
5854
+ Count non-NA cells for each column or row.
5855
+
5856
+ The values `None`, `NaN`, `NaT`, and optionally `numpy.inf` (depending
5857
+ on `pandas.options.mode.use_inf_as_na`) are considered NA.
5856
5858
5857
5859
Parameters
5858
5860
----------
5859
5861
axis : {0 or 'index', 1 or 'columns'}, default 0
5860
- 0 or 'index' for row-wise, 1 or 'columns' for column-wise
5861
- level : int or level name, default None
5862
- If the axis is a MultiIndex (hierarchical), count along a
5863
- particular level, collapsing into a DataFrame
5862
+ If 0 or 'index' counts are generated for each column.
5863
+ If 1 or 'columns' counts are generated for each **row**.
5864
+ level : int or str, optional
5865
+ If the axis is a `MultiIndex` (hierarchical), count along a
5866
+ particular `level`, collapsing into a `DataFrame`.
5867
+ A `str` specifies the level name.
5864
5868
numeric_only : boolean, default False
5865
- Include only float, int, boolean data
5869
+ Include only ` float`, ` int` or ` boolean` data.
5866
5870
5867
5871
Returns
5868
5872
-------
5869
- count : Series (or DataFrame if level specified)
5873
+ Series or DataFrame
5874
+ For each column/row the number of non-NA/null entries.
5875
+ If `level` is specified returns a `DataFrame`.
5876
+
5877
+ See Also
5878
+ --------
5879
+ Series.count: number of non-NA elements in a Series
5880
+ DataFrame.shape: number of DataFrame rows and columns (including NA
5881
+ elements)
5882
+ DataFrame.isna: boolean same-sized DataFrame showing places of NA
5883
+ elements
5884
+
5885
+ Examples
5886
+ --------
5887
+ Constructing DataFrame from a dictionary:
5888
+
5889
+ >>> df = pd.DataFrame({"Person":
5890
+ ... ["John", "Myla", None, "John", "Myla"],
5891
+ ... "Age": [24., np.nan, 21., 33, 26],
5892
+ ... "Single": [False, True, True, True, False]})
5893
+ >>> df
5894
+ Person Age Single
5895
+ 0 John 24.0 False
5896
+ 1 Myla NaN True
5897
+ 2 None 21.0 True
5898
+ 3 John 33.0 True
5899
+ 4 Myla 26.0 False
5900
+
5901
+ Notice the uncounted NA values:
5902
+
5903
+ >>> df.count()
5904
+ Person 4
5905
+ Age 4
5906
+ Single 5
5907
+ dtype: int64
5908
+
5909
+ Counts for each **row**:
5910
+
5911
+ >>> df.count(axis='columns')
5912
+ 0 3
5913
+ 1 2
5914
+ 2 2
5915
+ 3 3
5916
+ 4 3
5917
+ dtype: int64
5918
+
5919
+ Counts for one level of a `MultiIndex`:
5920
+
5921
+ >>> df.set_index(["Person", "Single"]).count(level="Person")
5922
+ Age
5923
+ Person
5924
+ John 2
5925
+ Myla 1
5870
5926
"""
5871
5927
axis = self ._get_axis_number (axis )
5872
5928
if level is not None :
0 commit comments