Skip to content

Commit 3bed3eb

Browse files
smusaliTomAugspurger
authored andcommitted
DOC: update the pandas.DataFrame.any docstring (#20217)
* pandas.DataFrame.any * Updated pandas.core.generic.py... * Removing extra files... * Requested changes... * Little update... * Updated * Added one more example related to Series and improved long desc... * Fixed some issues... * Updated Split Series and DataFrame Edgecase last in examples. Use axis='columns' Simplify extended description. * Explicit examples
1 parent 5f244d8 commit 3bed3eb

File tree

3 files changed

+76
-6
lines changed

3 files changed

+76
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,4 @@ doc/tmp.sv
109109
doc/source/styled.xlsx
110110
doc/source/templates/
111111
env/
112+
doc/source/savefig/

pandas/core/generic.py

+73-5
Original file line numberDiff line numberDiff line change
@@ -7583,8 +7583,7 @@ def _add_numeric_operations(cls):
75837583

75847584
cls.any = _make_logical_function(
75857585
cls, 'any', name, name2, axis_descr,
7586-
'Return whether any element is True over requested axis',
7587-
nanops.nanany, '', '')
7586+
_any_desc, nanops.nanany, _any_examples, _any_see_also)
75887587
cls.all = _make_logical_function(
75897588
cls, 'all', name, name2, axis_descr, _all_doc,
75907589
nanops.nanall, _all_examples, _all_see_also)
@@ -7848,7 +7847,8 @@ def _doc_parms(cls):
78487847
78497848
Parameters
78507849
----------
7851-
axis : %(axis_descr)s
7850+
axis : int, default 0
7851+
Select the axis which can be 0 for indices and 1 for columns.
78527852
skipna : boolean, default True
78537853
Exclude NA/null values. If an entire row/column is NA, the result
78547854
will be NA.
@@ -7866,8 +7866,8 @@ def _doc_parms(cls):
78667866
-------
78677867
%(outname)s : %(name1)s or %(name2)s (if level specified)
78687868
7869-
%(examples)s
7870-
%(see_also)s"""
7869+
%(see_also)s
7870+
%(examples)s"""
78717871

78727872
_all_doc = """\
78737873
Return whether all elements are True over series or dataframe axis.
@@ -7938,6 +7938,74 @@ def _doc_parms(cls):
79387938
79397939
"""
79407940

7941+
_any_see_also = """\
7942+
See Also
7943+
--------
7944+
pandas.DataFrame.all : Return whether all elements are True.
7945+
"""
7946+
7947+
_any_desc = """\
7948+
Return whether any element is True over requested axis.
7949+
7950+
Unlike :meth:`DataFrame.all`, this performs an *or* operation. If any of the
7951+
values along the specified axis is True, this will return True."""
7952+
7953+
_any_examples = """\
7954+
Examples
7955+
--------
7956+
**Series**
7957+
7958+
For Series input, the output is a scalar indicating whether any element
7959+
is True.
7960+
7961+
>>> pd.Series([True, False]).any()
7962+
True
7963+
7964+
**DataFrame**
7965+
7966+
Whether each column contains at least one True element (the default).
7967+
7968+
>>> df = pd.DataFrame({"A": [1, 2], "B": [0, 2], "C": [0, 0]})
7969+
>>> df
7970+
A B C
7971+
0 1 0 0
7972+
1 2 2 0
7973+
7974+
>>> df.any()
7975+
A True
7976+
B True
7977+
C False
7978+
dtype: bool
7979+
7980+
Aggregating over the columns.
7981+
7982+
>>> df = pd.DataFrame({"A": [True, False], "B": [1, 2]})
7983+
>>> df
7984+
A B
7985+
0 True 1
7986+
1 False 2
7987+
7988+
>>> df.any(axis='columns')
7989+
0 True
7990+
1 True
7991+
dtype: bool
7992+
7993+
>>> df = pd.DataFrame({"A": [True, False], "B": [1, 0]})
7994+
>>> df
7995+
A B
7996+
0 True 1
7997+
1 False 0
7998+
7999+
>>> df.any(axis='columns')
8000+
0 True
8001+
1 False
8002+
dtype: bool
8003+
8004+
`any` for an empty DataFrame is an empty Series.
8005+
8006+
>>> pd.DataFrame([]).any()
8007+
Series([], dtype: bool)
8008+
"""
79418009

79428010
_sum_examples = """\
79438011
Examples

pandas/core/groupby.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,8 @@ def result_to_bool(result):
12451245
@Substitution(name='groupby')
12461246
@Appender(_doc_template)
12471247
def any(self, skipna=True):
1248-
"""Returns True if any value in the group is truthful, else False
1248+
"""
1249+
Returns True if any value in the group is truthful, else False
12491250
12501251
Parameters
12511252
----------

0 commit comments

Comments
 (0)