@@ -6596,9 +6596,10 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
6596
6596
return self ._constructor (new_data ).__finalize__ (self )
6597
6597
6598
6598
_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`.
6602
6603
6603
6604
Parameters
6604
6605
----------
@@ -6623,23 +6624,26 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
6623
6624
A callable can be used as other.
6624
6625
6625
6626
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`
6633
6633
Note that currently this parameter won't affect
6634
6634
the results and will always coerce to a suitable dtype.
6635
6635
6636
+ - `raise` : allow exceptions to be raised.
6637
+ - `ignore` : suppress exceptions. On error return original object.
6638
+
6636
6639
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).
6638
6641
raise_on_error : boolean, default True
6639
6642
Whether to raise on invalid data types (e.g. trying to where on
6640
- strings)
6643
+ strings).
6641
6644
6642
6645
.. deprecated:: 0.21.0
6646
+ Use `error`.
6643
6647
6644
6648
Returns
6645
6649
-------
@@ -6659,6 +6663,10 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
6659
6663
For further details and examples see the ``%(name)s`` documentation in
6660
6664
:ref:`indexing <indexing.where_mask>`.
6661
6665
6666
+ See Also
6667
+ --------
6668
+ :func:`DataFrame.%(name_other)s` : Return an object of same shape as self
6669
+
6662
6670
Examples
6663
6671
--------
6664
6672
>>> s = pd.Series(range(5))
@@ -6668,20 +6676,23 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
6668
6676
2 2.0
6669
6677
3 3.0
6670
6678
4 4.0
6679
+ dtype: float64
6671
6680
6672
6681
>>> s.mask(s > 0)
6673
6682
0 0.0
6674
6683
1 NaN
6675
6684
2 NaN
6676
6685
3 NaN
6677
6686
4 NaN
6687
+ dtype: float64
6678
6688
6679
6689
>>> 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
6685
6696
6686
6697
>>> df = pd.DataFrame(np.arange(10).reshape(-1, 2), columns=['A', 'B'])
6687
6698
>>> m = df %% 3 == 0
@@ -6706,10 +6717,6 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
6706
6717
2 True True
6707
6718
3 True True
6708
6719
4 True True
6709
-
6710
- See Also
6711
- --------
6712
- :func:`DataFrame.%(name_other)s`
6713
6720
""" )
6714
6721
6715
6722
@Appender (_shared_docs ['where' ] % dict (_shared_doc_kwargs , cond = "True" ,
0 commit comments