diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 48366a286ac05..8da678e0adec0 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7778,9 +7778,7 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None, return self._constructor(new_data).__finalize__(self) _shared_docs['where'] = (""" - Return an object of same shape as self and whose corresponding - entries are from self where `cond` is %(cond)s and otherwise are from - `other`. + Replace values where the condition is %(cond_rev)s. Parameters ---------- @@ -7805,24 +7803,28 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None, A callable can be used as other. inplace : boolean, default False - Whether to perform the operation in place on the data - axis : alignment axis if needed, default None - level : alignment level if needed, default None - errors : str, {'raise', 'ignore'}, default 'raise' - - ``raise`` : allow exceptions to be raised - - ``ignore`` : suppress exceptions. On error return original object - + Whether to perform the operation in place on the data. + axis : int, default None + Alignment axis if needed. + level : int, default None + Alignment level if needed. + errors : str, {'raise', 'ignore'}, default `raise` Note that currently this parameter won't affect the results and will always coerce to a suitable dtype. + - `raise` : allow exceptions to be raised. + - `ignore` : suppress exceptions. On error return original object. + try_cast : boolean, default False - try to cast the result back to the input type (if possible), + Try to cast the result back to the input type (if possible). raise_on_error : boolean, default True Whether to raise on invalid data types (e.g. trying to where on - strings) + strings). .. deprecated:: 0.21.0 + Use `errors`. + Returns ------- wh : same type as caller @@ -7841,6 +7843,11 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None, For further details and examples see the ``%(name)s`` documentation in :ref:`indexing `. + See Also + -------- + :func:`DataFrame.%(name_other)s` : Return an object of same shape as + self + Examples -------- >>> s = pd.Series(range(5)) @@ -7850,6 +7857,7 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None, 2 2.0 3 3.0 4 4.0 + dtype: float64 >>> s.mask(s > 0) 0 0.0 @@ -7857,13 +7865,15 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None, 2 NaN 3 NaN 4 NaN + dtype: float64 >>> s.where(s > 1, 10) - 0 10.0 - 1 10.0 - 2 2.0 - 3 3.0 - 4 4.0 + 0 10 + 1 10 + 2 2 + 3 3 + 4 4 + dtype: int64 >>> df = pd.DataFrame(np.arange(10).reshape(-1, 2), columns=['A', 'B']) >>> m = df %% 3 == 0 @@ -7888,10 +7898,6 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None, 2 True True 3 True True 4 True True - - See Also - -------- - :func:`DataFrame.%(name_other)s` """) @Appender(_shared_docs['where'] % dict(_shared_doc_kwargs, cond="True",