Skip to content

Commit a7b187a

Browse files
Moisandatapythonista
authored andcommitted
DOC: Fix DataFrame.nunique docstring and doctests (#23891)
* Remove repetition in long description * swap sentences
1 parent 002ab43 commit a7b187a

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

ci/code_checks.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
147147

148148
MSG='Doctests frame.py' ; echo $MSG
149149
pytest -q --doctest-modules pandas/core/frame.py \
150-
-k"-axes -combine -itertuples -join -nunique -pivot_table -quantile -query -reindex -reindex_axis -replace -round -set_index -stack"
150+
-k"-axes -combine -itertuples -join -pivot_table -quantile -query -reindex -reindex_axis -replace -round -set_index -stack"
151151
RET=$(($RET + $?)) ; echo $MSG "DONE"
152152

153153
MSG='Doctests series.py' ; echo $MSG

pandas/core/frame.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -7279,32 +7279,43 @@ def f(x):
72797279

72807280
def nunique(self, axis=0, dropna=True):
72817281
"""
7282-
Return Series with number of distinct observations over requested
7283-
axis.
7282+
Count distinct observations over requested axis.
7283+
7284+
Return Series with number of distinct observations. Can ignore NaN
7285+
values.
72847286
72857287
.. versionadded:: 0.20.0
72867288
72877289
Parameters
72887290
----------
72897291
axis : {0 or 'index', 1 or 'columns'}, default 0
7290-
dropna : boolean, default True
7292+
The axis to use. 0 or 'index' for row-wise, 1 or 'columns' for
7293+
column-wise.
7294+
dropna : bool, default True
72917295
Don't include NaN in the counts.
72927296
72937297
Returns
72947298
-------
72957299
nunique : Series
72967300
7301+
See Also
7302+
--------
7303+
Series.nunique: Method nunique for Series.
7304+
DataFrame.count: Count non-NA cells for each column or row.
7305+
72977306
Examples
72987307
--------
72997308
>>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [1, 1, 1]})
73007309
>>> df.nunique()
73017310
A 3
73027311
B 1
7312+
dtype: int64
73037313
73047314
>>> df.nunique(axis=1)
73057315
0 1
73067316
1 2
73077317
2 2
7318+
dtype: int64
73087319
"""
73097320
return self.apply(Series.nunique, axis=axis, dropna=dropna)
73107321

0 commit comments

Comments
 (0)