@@ -1920,6 +1920,68 @@ def f(x):
19201920
19211921 return obj
19221922
1923+ def clip (self , lower = None , upper = None , out = None ):
1924+ """
1925+ Trim values at input threshold(s)
1926+
1927+ Parameters
1928+ ----------
1929+ lower : float, default None
1930+ upper : float, default None
1931+
1932+ Returns
1933+ -------
1934+ clipped : Series
1935+ """
1936+ if out is not None : # pragma: no cover
1937+ raise Exception ('out argument is not supported yet' )
1938+
1939+ # GH 2747 (arguments were reversed)
1940+ if lower is not None and upper is not None :
1941+ lower , upper = min (lower , upper ), max (lower , upper )
1942+
1943+ result = self
1944+ if lower is not None :
1945+ result = result .clip_lower (lower )
1946+ if upper is not None :
1947+ result = result .clip_upper (upper )
1948+
1949+ return result
1950+
1951+ def clip_upper (self , threshold ):
1952+ """
1953+ Return copy of input with values above given value truncated
1954+
1955+ See also
1956+ --------
1957+ clip
1958+
1959+ Returns
1960+ -------
1961+ clipped : same type as input
1962+ """
1963+ if isnull (threshold ):
1964+ raise ValueError ("Cannot use an NA value as a clip threshold" )
1965+
1966+ return self .where ((self <= threshold ) | isnull (self ), threshold )
1967+
1968+ def clip_lower (self , threshold ):
1969+ """
1970+ Return copy of the input with values below given value truncated
1971+
1972+ See also
1973+ --------
1974+ clip
1975+
1976+ Returns
1977+ -------
1978+ clipped : same type as input
1979+ """
1980+ if isnull (threshold ):
1981+ raise ValueError ("Cannot use an NA value as a clip threshold" )
1982+
1983+ return self .where ((self >= threshold ) | isnull (self ), threshold )
1984+
19231985 def groupby (self , by = None , axis = 0 , level = None , as_index = True , sort = True ,
19241986 group_keys = True , squeeze = False ):
19251987 """
0 commit comments