@@ -5825,20 +5825,24 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
5825
5825
5826
5826
_shared_docs ['where' ] = ("""
5827
5827
Return an object of same shape as self and whose corresponding
5828
- entries are from self where cond is %(cond)s and otherwise are from
5829
- other.
5828
+ entries are from self where ` cond` is %(cond)s and otherwise are from
5829
+ ` other` .
5830
5830
5831
5831
Parameters
5832
5832
----------
5833
5833
cond : boolean %(klass)s, array-like, or callable
5834
- If cond is callable, it is computed on the %(klass)s and
5834
+ Where `cond` is %(cond)s, keep the original value. Where
5835
+ %(cond_rev)s, replace with corresponding value from `other`.
5836
+ If `cond` is callable, it is computed on the %(klass)s and
5835
5837
should return boolean %(klass)s or array. The callable must
5836
5838
not change input %(klass)s (though pandas doesn't check it).
5837
5839
5838
5840
.. versionadded:: 0.18.1
5839
5841
A callable can be used as cond.
5840
5842
5841
5843
other : scalar, %(klass)s, or callable
5844
+ Entries where `cond` is %(cond_rev)s are replaced with
5845
+ corresponding value from `other`.
5842
5846
If other is callable, it is computed on the %(klass)s and
5843
5847
should return scalar or %(klass)s. The callable must not
5844
5848
change input %(klass)s (though pandas doesn't check it).
@@ -5884,6 +5888,20 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
5884
5888
3 3.0
5885
5889
4 4.0
5886
5890
5891
+ >>> s.mask(s > 0)
5892
+ 0 0.0
5893
+ 1 NaN
5894
+ 2 NaN
5895
+ 3 NaN
5896
+ 4 NaN
5897
+
5898
+ >>> s.where(s > 1, 10)
5899
+ 0 10.0
5900
+ 1 10.0
5901
+ 2 2.0
5902
+ 3 3.0
5903
+ 4 4.0
5904
+
5887
5905
>>> df = pd.DataFrame(np.arange(10).reshape(-1, 2), columns=['A', 'B'])
5888
5906
>>> m = df %% 3 == 0
5889
5907
>>> df.where(m, -df)
@@ -5914,7 +5932,8 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
5914
5932
""" )
5915
5933
5916
5934
@Appender (_shared_docs ['where' ] % dict (_shared_doc_kwargs , cond = "True" ,
5917
- name = 'where' , name_other = 'mask' ))
5935
+ cond_rev = "False" , name = 'where' ,
5936
+ name_other = 'mask' ))
5918
5937
def where (self , cond , other = np .nan , inplace = False , axis = None , level = None ,
5919
5938
try_cast = False , raise_on_error = True ):
5920
5939
@@ -5923,7 +5942,8 @@ def where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
5923
5942
raise_on_error )
5924
5943
5925
5944
@Appender (_shared_docs ['where' ] % dict (_shared_doc_kwargs , cond = "False" ,
5926
- name = 'mask' , name_other = 'where' ))
5945
+ cond_rev = "True" , name = 'mask' ,
5946
+ name_other = 'where' ))
5927
5947
def mask (self , cond , other = np .nan , inplace = False , axis = None , level = None ,
5928
5948
try_cast = False , raise_on_error = True ):
5929
5949
0 commit comments