@@ -8361,22 +8361,24 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
8361
8361
errors = errors )
8362
8362
8363
8363
_shared_docs ['shift' ] = ("""
8364
- Shift index by desired number of periods with an optional time freq
8364
+ Shift index by desired number of periods with an optional time `freq`.
8365
+
8366
+ When `freq` is not passed, shift the index without realigning the data.
8367
+ If `freq` is passed (in this case, the index must be date or datetime,
8368
+ or it will raises a `NotImplementedError`), the index will be
8369
+ increased using the periods and the `freq`.
8365
8370
8366
8371
Parameters
8367
8372
----------
8368
8373
periods : int
8369
- Number of periods to move, can be positive or negative.
8374
+ Number of periods to shift; can be positive or negative.
8370
8375
freq : DateOffset, timedelta, or time rule string, optional
8371
8376
Increment to use from the tseries module or time rule (e.g. 'EOM').
8372
- See Notes.
8373
- axis : %(axes_single_arg)s
8374
-
8375
- See Also
8376
- --------
8377
- Index.shift : Shift values of Index.
8378
- DatetimeIndex.shift : Shift values of DatetimeIndex.
8379
- PeriodIndex.shift : Shift values of PeriodIndex.
8377
+ If `freq` is specified then the index values are shifted but the
8378
+ data is not realigned. That is, use `freq` if you would like to
8379
+ extend the index when shifting and preserve the original data.
8380
+ axis : {0 or ‘index’, 1 or ‘columns’, None}, default None
8381
+ Shift direction.
8380
8382
8381
8383
Notes
8382
8384
-----
@@ -8386,7 +8388,75 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
8386
8388
8387
8389
Returns
8388
8390
-------
8389
- shifted : %(klass)s
8391
+ %(klass)s
8392
+ Copy of input object, shifted.
8393
+
8394
+ See Also
8395
+ --------
8396
+ Index.shift : Shift values of Index.
8397
+ DatetimeIndex.shift : Shift values of DatetimeIndex.
8398
+ PeriodIndex.shift : Shift values of PeriodIndex.
8399
+ tshift : Shift the time index, using the index’s frequency if
8400
+ available.
8401
+
8402
+ Examples
8403
+ --------
8404
+ >>> df = pd.DataFrame({'Col1': [10, 20, 15, 30, 45],
8405
+ ... 'Col2': [13, 23, 18, 33, 48],
8406
+ ... 'Col3': [17, 27, 22, 37, 52]})
8407
+
8408
+ >>> df.shift(periods=3)
8409
+ Col1 Col2 Col3
8410
+ 0 NaN NaN NaN
8411
+ 1 NaN NaN NaN
8412
+ 2 NaN NaN NaN
8413
+ 3 10.0 13.0 17.0
8414
+ 4 20.0 23.0 27.0
8415
+
8416
+ >>> df.shift(periods=1, axis=1)
8417
+ Col1 Col2 Col3
8418
+ 0 NaN 10.0 13.0
8419
+ 1 NaN 20.0 23.0
8420
+ 2 NaN 15.0 18.0
8421
+ 3 NaN 30.0 33.0
8422
+ 4 NaN 45.0 48.0
8423
+
8424
+ **freq parameter**
8425
+
8426
+ When using the freq parameter with a :class:pandas.DateTimeIndex
8427
+ the index values are shifted but the data is not realigned.
8428
+
8429
+ >>> names = ['Joaquim', 'Maria', 'Emanuel', 'Jussara', 'Geraldo']
8430
+ >>> dates = pd.date_range(start='2018-03-05 11:15:00',
8431
+ ... freq='5D', periods=5)
8432
+ >>> df = pd.DataFrame(data={'names': names}, index=dates)
8433
+ >>> df
8434
+ names
8435
+ 2018-03-05 11:15:00 Joaquim
8436
+ 2018-03-10 11:15:00 Maria
8437
+ 2018-03-15 11:15:00 Emanuel
8438
+ 2018-03-20 11:15:00 Jussara
8439
+ 2018-03-25 11:15:00 Geraldo
8440
+
8441
+ Shift the index by 2 days (offset-alias 'D').
8442
+
8443
+ >>> df.shift(periods=2, freq='D')
8444
+ names
8445
+ 2018-03-07 11:15:00 Joaquim
8446
+ 2018-03-12 11:15:00 Maria
8447
+ 2018-03-17 11:15:00 Emanuel
8448
+ 2018-03-22 11:15:00 Jussara
8449
+ 2018-03-27 11:15:00 Geraldo
8450
+
8451
+ Shift the index by 75 minutes (offset-alias 'min').
8452
+
8453
+ >>> df.shift(periods=75, freq='min')
8454
+ names
8455
+ 2018-03-05 12:30:00 Joaquim
8456
+ 2018-03-10 12:30:00 Maria
8457
+ 2018-03-15 12:30:00 Emanuel
8458
+ 2018-03-20 12:30:00 Jussara
8459
+ 2018-03-25 12:30:00 Geraldo
8390
8460
""" )
8391
8461
8392
8462
@Appender (_shared_docs ['shift' ] % _shared_doc_kwargs )
0 commit comments