@@ -6324,23 +6324,72 @@ def tshift(self, periods=1, freq=None, axis=0):
63246324 return self ._constructor (new_data ).__finalize__ (self )
63256325
63266326 def truncate (self , before = None , after = None , axis = None , copy = True ):
6327- """Truncates a sorted NDFrame before and/or after some particular
6328- index value. If the axis contains only datetime values, before/after
6329- parameters are converted to datetime values.
6327+ """
6328+ Truncates a sorted DataFrame/Series before and/or after some
6329+ particular index value. If the axis contains only datetime values,
6330+ before/after parameters are converted to datetime values.
63306331
63316332 Parameters
63326333 ----------
6333- before : date
6334- Truncate before index value
6335- after : date
6336- Truncate after index value
6337- axis : the truncation axis, defaults to the stat axis
6334+ before : date, string, int
6335+ Truncate all rows before this index value
6336+ after : date, string, int
6337+ Truncate all rows after this index value
6338+ axis : {0 or 'index', 1 or 'columns'}
6339+
6340+ * 0 or 'index': apply truncation to rows
6341+ * 1 or 'columns': apply truncation to columns
6342+ Default is stat axis for given data type (0 for Series and
6343+ DataFrames, 1 for Panels)
63386344 copy : boolean, default is True,
63396345 return a copy of the truncated section
63406346
63416347 Returns
63426348 -------
63436349 truncated : type of caller
6350+
6351+ Examples
6352+ --------
6353+ >>> df = pd.DataFrame({'A': ['a', 'b', 'c', 'd', 'e'],
6354+ ... 'B': ['f', 'g', 'h', 'i', 'j'],
6355+ ... 'C': ['k', 'l', 'm', 'n', 'o']},
6356+ ... index=[1, 2, 3, 4, 5])
6357+ >>> df.truncate(before=2, after=4)
6358+ A B C
6359+ 2 b g l
6360+ 3 c h m
6361+ 4 d i n
6362+ >>> df = pd.DataFrame({'A': [1, 2, 3, 4, 5],
6363+ ... 'B': [6, 7, 8, 9, 10],
6364+ ... 'C': [11, 12, 13, 14, 15]},
6365+ ... index=['a', 'b', 'c', 'd', 'e'])
6366+ >>> df.truncate(before='b', after='d')
6367+ A B C
6368+ b 2 7 12
6369+ c 3 8 13
6370+ d 4 9 14
6371+
6372+ The index values in ``truncate`` can be datetimes or string
6373+ dates. Note that ``truncate`` assumes a 0 value for any unspecified
6374+ date component in a ``DatetimeIndex`` in contrast to slicing which
6375+ returns any partially matching dates.
6376+
6377+ >>> dates = pd.date_range('2016-01-01', '2016-02-01', freq='s')
6378+ >>> df = pd.DataFrame(index=dates, data={'A': 1})
6379+ >>> df.truncate('2016-01-05', '2016-01-10').tail()
6380+ A
6381+ 2016-01-09 23:59:56 1
6382+ 2016-01-09 23:59:57 1
6383+ 2016-01-09 23:59:58 1
6384+ 2016-01-09 23:59:59 1
6385+ 2016-01-10 00:00:00 1
6386+ >>> df.loc['2016-01-05':'2016-01-10', :].tail()
6387+ A
6388+ 2016-01-10 23:59:55 1
6389+ 2016-01-10 23:59:56 1
6390+ 2016-01-10 23:59:57 1
6391+ 2016-01-10 23:59:58 1
6392+ 2016-01-10 23:59:59 1
63446393 """
63456394
63466395 if axis is None :
0 commit comments