Skip to content

Commit 3391c22

Browse files
simobassoWillAyd
authored andcommitted
DOC: update the pandas.Series.where docstring (pandas-dev#20165)
1 parent b058e37 commit 3391c22

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

pandas/core/generic.py

+27-21
Original file line numberDiff line numberDiff line change
@@ -7778,9 +7778,7 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
77787778
return self._constructor(new_data).__finalize__(self)
77797779

77807780
_shared_docs['where'] = ("""
7781-
Return an object of same shape as self and whose corresponding
7782-
entries are from self where `cond` is %(cond)s and otherwise are from
7783-
`other`.
7781+
Replace values where the condition is %(cond_rev)s.
77847782
77857783
Parameters
77867784
----------
@@ -7805,24 +7803,28 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
78057803
A callable can be used as other.
78067804
78077805
inplace : boolean, default False
7808-
Whether to perform the operation in place on the data
7809-
axis : alignment axis if needed, default None
7810-
level : alignment level if needed, default None
7811-
errors : str, {'raise', 'ignore'}, default 'raise'
7812-
- ``raise`` : allow exceptions to be raised
7813-
- ``ignore`` : suppress exceptions. On error return original object
7814-
7806+
Whether to perform the operation in place on the data.
7807+
axis : int, default None
7808+
Alignment axis if needed.
7809+
level : int, default None
7810+
Alignment level if needed.
7811+
errors : str, {'raise', 'ignore'}, default `raise`
78157812
Note that currently this parameter won't affect
78167813
the results and will always coerce to a suitable dtype.
78177814
7815+
- `raise` : allow exceptions to be raised.
7816+
- `ignore` : suppress exceptions. On error return original object.
7817+
78187818
try_cast : boolean, default False
7819-
try to cast the result back to the input type (if possible),
7819+
Try to cast the result back to the input type (if possible).
78207820
raise_on_error : boolean, default True
78217821
Whether to raise on invalid data types (e.g. trying to where on
7822-
strings)
7822+
strings).
78237823
78247824
.. deprecated:: 0.21.0
78257825
7826+
Use `errors`.
7827+
78267828
Returns
78277829
-------
78287830
wh : same type as caller
@@ -7841,6 +7843,11 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
78417843
For further details and examples see the ``%(name)s`` documentation in
78427844
:ref:`indexing <indexing.where_mask>`.
78437845
7846+
See Also
7847+
--------
7848+
:func:`DataFrame.%(name_other)s` : Return an object of same shape as
7849+
self
7850+
78447851
Examples
78457852
--------
78467853
>>> s = pd.Series(range(5))
@@ -7850,20 +7857,23 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
78507857
2 2.0
78517858
3 3.0
78527859
4 4.0
7860+
dtype: float64
78537861
78547862
>>> s.mask(s > 0)
78557863
0 0.0
78567864
1 NaN
78577865
2 NaN
78587866
3 NaN
78597867
4 NaN
7868+
dtype: float64
78607869
78617870
>>> s.where(s > 1, 10)
7862-
0 10.0
7863-
1 10.0
7864-
2 2.0
7865-
3 3.0
7866-
4 4.0
7871+
0 10
7872+
1 10
7873+
2 2
7874+
3 3
7875+
4 4
7876+
dtype: int64
78677877
78687878
>>> df = pd.DataFrame(np.arange(10).reshape(-1, 2), columns=['A', 'B'])
78697879
>>> m = df %% 3 == 0
@@ -7888,10 +7898,6 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
78887898
2 True True
78897899
3 True True
78907900
4 True True
7891-
7892-
See Also
7893-
--------
7894-
:func:`DataFrame.%(name_other)s`
78957901
""")
78967902

78977903
@Appender(_shared_docs['where'] % dict(_shared_doc_kwargs, cond="True",

0 commit comments

Comments
 (0)