@@ -1696,6 +1696,49 @@ def kurt(self):
1696
1696
def where (self , cond , other ):
1697
1697
"""Replace values where the condition is False.
1698
1698
1699
+ **Examples:**
1700
+
1701
+ >>> import bigframes.pandas as bpd
1702
+ >>> bpd.options.display.progress_bar = None
1703
+
1704
+ >>> s = bpd.Series([10, 11, 12, 13, 14])
1705
+ >>> s
1706
+ 0 10
1707
+ 1 11
1708
+ 2 12
1709
+ 3 13
1710
+ 4 14
1711
+ dtype: Int64
1712
+
1713
+ You can filter the values in the Series based on a condition. The values
1714
+ matching the condition would be kept, and not matching would be replaced.
1715
+ The default replacement value is ``NA``.
1716
+
1717
+ >>> s.where(s % 2 == 0)
1718
+ 0 10
1719
+ 1 <NA>
1720
+ 2 12
1721
+ 3 <NA>
1722
+ 4 14
1723
+ dtype: Int64
1724
+
1725
+ You can specify a custom replacement value for non-matching values.
1726
+
1727
+ >>> s.where(s % 2 == 0, -1)
1728
+ 0 10
1729
+ 1 -1
1730
+ 2 12
1731
+ 3 -1
1732
+ 4 14
1733
+ dtype: Int64
1734
+ >>> s.where(s % 2 == 0, 100*s)
1735
+ 0 10
1736
+ 1 1100
1737
+ 2 12
1738
+ 3 1300
1739
+ 4 14
1740
+ dtype: Int64
1741
+
1699
1742
Args:
1700
1743
cond (bool Series/DataFrame, array-like, or callable):
1701
1744
Where cond is True, keep the original value. Where False, replace
@@ -1720,6 +1763,77 @@ def where(self, cond, other):
1720
1763
def mask (self , cond , other ):
1721
1764
"""Replace values where the condition is True.
1722
1765
1766
+ **Examples:**
1767
+
1768
+ >>> import bigframes.pandas as bpd
1769
+ >>> bpd.options.display.progress_bar = None
1770
+
1771
+ >>> s = bpd.Series([10, 11, 12, 13, 14])
1772
+ >>> s
1773
+ 0 10
1774
+ 1 11
1775
+ 2 12
1776
+ 3 13
1777
+ 4 14
1778
+ dtype: Int64
1779
+
1780
+ You can mask the values in the Series based on a condition. The values
1781
+ matching the condition would be masked.
1782
+
1783
+ >>> s.mask(s % 2 == 0)
1784
+ 0 <NA>
1785
+ 1 11
1786
+ 2 <NA>
1787
+ 3 13
1788
+ 4 <NA>
1789
+ dtype: Int64
1790
+
1791
+ You can specify a custom mask value.
1792
+
1793
+ >>> s.mask(s % 2 == 0, -1)
1794
+ 0 -1
1795
+ 1 11
1796
+ 2 -1
1797
+ 3 13
1798
+ 4 -1
1799
+ dtype: Int64
1800
+ >>> s.mask(s % 2 == 0, 100*s)
1801
+ 0 1000
1802
+ 1 11
1803
+ 2 1200
1804
+ 3 13
1805
+ 4 1400
1806
+ dtype: Int64
1807
+
1808
+ You can also use a remote function to evaluate the mask condition. This
1809
+ is useful in situation such as the following, where the mask
1810
+ condition is evaluated based on a complicated business logic which cannot
1811
+ be expressed in form of a Series.
1812
+
1813
+ >>> @bpd.remote_function([str], bool, reuse=False)
1814
+ ... def should_mask(name):
1815
+ ... hash = 0
1816
+ ... for char_ in name:
1817
+ ... hash += ord(char_)
1818
+ ... return hash % 2 == 0
1819
+
1820
+ >>> s = bpd.Series(["Alice", "Bob", "Caroline"])
1821
+ >>> s
1822
+ 0 Alice
1823
+ 1 Bob
1824
+ 2 Caroline
1825
+ dtype: string
1826
+ >>> s.mask(should_mask)
1827
+ 0 <NA>
1828
+ 1 Bob
1829
+ 2 Caroline
1830
+ dtype: string
1831
+ >>> s.mask(should_mask, "REDACTED")
1832
+ 0 REDACTED
1833
+ 1 Bob
1834
+ 2 Caroline
1835
+ dtype: string
1836
+
1723
1837
Args:
1724
1838
cond (bool Series/DataFrame, array-like, or callable):
1725
1839
Where cond is False, keep the original value. Where True, replace
0 commit comments