Skip to content

Commit 5bc9c63

Browse files
committed
DOC: Improved the docstring of pandas.Series.where
1 parent 4131149 commit 5bc9c63

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

pandas/core/generic.py

+28-21
Original file line numberDiff line numberDiff line change
@@ -6596,9 +6596,10 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
65966596
return self._constructor(new_data).__finalize__(self)
65976597

65986598
_shared_docs['where'] = ("""
6599-
Return an object of same shape as self and whose corresponding
6600-
entries are from self where `cond` is %(cond)s and otherwise are from
6601-
`other`.
6599+
Replace values that don't respect a `cond` condition.
6600+
6601+
Return an object of same shape as self with entries that
6602+
not satisfy a `cond` is %(cond)s are replaced by `other`.
66026603
66036604
Parameters
66046605
----------
@@ -6623,23 +6624,26 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
66236624
A callable can be used as other.
66246625
66256626
inplace : boolean, default False
6626-
Whether to perform the operation in place on the data
6627-
axis : alignment axis if needed, default None
6628-
level : alignment level if needed, default None
6629-
errors : str, {'raise', 'ignore'}, default 'raise'
6630-
- ``raise`` : allow exceptions to be raised
6631-
- ``ignore`` : suppress exceptions. On error return original object
6632-
6627+
Whether to perform the operation in place on the data.
6628+
axis : int, default None
6629+
Alignment axis if needed.
6630+
level : int, default None
6631+
Alignment level if needed.
6632+
errors : str, {'raise', 'ignore'}, default `raise`
66336633
Note that currently this parameter won't affect
66346634
the results and will always coerce to a suitable dtype.
66356635
6636+
- `raise` : allow exceptions to be raised.
6637+
- `ignore` : suppress exceptions. On error return original object.
6638+
66366639
try_cast : boolean, default False
6637-
try to cast the result back to the input type (if possible),
6640+
Try to cast the result back to the input type (if possible).
66386641
raise_on_error : boolean, default True
66396642
Whether to raise on invalid data types (e.g. trying to where on
6640-
strings)
6643+
strings).
66416644
66426645
.. deprecated:: 0.21.0
6646+
Use `error`.
66436647
66446648
Returns
66456649
-------
@@ -6659,6 +6663,10 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
66596663
For further details and examples see the ``%(name)s`` documentation in
66606664
:ref:`indexing <indexing.where_mask>`.
66616665
6666+
See Also
6667+
--------
6668+
:func:`DataFrame.%(name_other)s` : Return an object of same shape as self
6669+
66626670
Examples
66636671
--------
66646672
>>> s = pd.Series(range(5))
@@ -6668,20 +6676,23 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
66686676
2 2.0
66696677
3 3.0
66706678
4 4.0
6679+
dtype: float64
66716680
66726681
>>> s.mask(s > 0)
66736682
0 0.0
66746683
1 NaN
66756684
2 NaN
66766685
3 NaN
66776686
4 NaN
6687+
dtype: float64
66786688
66796689
>>> s.where(s > 1, 10)
6680-
0 10.0
6681-
1 10.0
6682-
2 2.0
6683-
3 3.0
6684-
4 4.0
6690+
0 10
6691+
1 10
6692+
2 2
6693+
3 3
6694+
4 4
6695+
dtype: int64
66856696
66866697
>>> df = pd.DataFrame(np.arange(10).reshape(-1, 2), columns=['A', 'B'])
66876698
>>> m = df %% 3 == 0
@@ -6706,10 +6717,6 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
67066717
2 True True
67076718
3 True True
67086719
4 True True
6709-
6710-
See Also
6711-
--------
6712-
:func:`DataFrame.%(name_other)s`
67136720
""")
67146721

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

0 commit comments

Comments
 (0)