@@ -6330,17 +6330,64 @@ def truncate(self, before=None, after=None, axis=None, copy=True):
6330
6330
6331
6331
Parameters
6332
6332
----------
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
6333
+ before : date, string, int
6334
+ Truncate all rows before this index value
6335
+ after : date, string, int
6336
+ Truncate all rows after this index value
6337
+ axis : {0 or 'index', 1 or 'columns'}
6338
+ * 0 or 'index': apply truncation to rows
6339
+ * 1 or 'columns': apply truncation to columns
6340
+ Default is stat axis for given data type (0 for Series and
6341
+ DataFrames, 1 for Panels)
6338
6342
copy : boolean, default is True,
6339
6343
return a copy of the truncated section
6340
6344
6341
6345
Returns
6342
6346
-------
6343
6347
truncated : type of caller
6348
+
6349
+ Examples
6350
+ --------
6351
+ >>> df = pd.DataFrame({'A': ['a', 'b', 'c', 'd', 'e'],
6352
+ ... 'B': ['f', 'g', 'h', 'i', 'j'],
6353
+ ... 'C': ['k', 'l', 'm', 'n', 'o']},
6354
+ ... index=[1, 2, 3, 4, 5])
6355
+ >>> df.truncate(before=2, after=4)
6356
+ A B C
6357
+ 2 b g l
6358
+ 3 c h m
6359
+ 4 d i n
6360
+ >>> df = pd.DataFrame({'A': [1, 2, 3, 4, 5],
6361
+ ... 'B': [6, 7, 8, 9, 10],
6362
+ ... 'C': [11, 12, 13, 14, 15]},
6363
+ ... index=['a', 'b', 'c', 'd', 'e'])
6364
+ >>> df.truncate(before='b', after='d')
6365
+ A B C
6366
+ b 2 7 12
6367
+ c 3 8 13
6368
+ d 4 9 14
6369
+
6370
+ The index values in ``truncate`` can be datetimes or (partial) string
6371
+ dates. Note that ``truncate`` assumes a 0 value for any unspecified
6372
+ date component in a ``DatetimeIndex`` in contrast to slicing which
6373
+ returns any partially matching dates.
6374
+
6375
+ >>> dates = pd.date_range('2016-1-1', '2016-2-1', freq='s')
6376
+ >>> df = pd.DataFrame(index=dates, data={'A': 1})
6377
+ >>> df.truncate('2016-1-5', '2016-1-10').tail()
6378
+ A
6379
+ 2016-01-09 23:59:56 1
6380
+ 2016-01-09 23:59:57 1
6381
+ 2016-01-09 23:59:58 1
6382
+ 2016-01-09 23:59:59 1
6383
+ 2016-01-10 00:00:00 1
6384
+ >>> df.loc['2016-1-5':'2016-1-10', :].tail()
6385
+ A
6386
+ 2016-01-10 23:59:55 1
6387
+ 2016-01-10 23:59:56 1
6388
+ 2016-01-10 23:59:57 1
6389
+ 2016-01-10 23:59:58 1
6390
+ 2016-01-10 23:59:59 1
6344
6391
"""
6345
6392
6346
6393
if axis is None :
0 commit comments