@@ -8421,32 +8421,59 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
8421
8421
errors = errors )
8422
8422
8423
8423
_shared_docs ['shift' ] = ("""
8424
- Shift index by desired number of periods with an optional time freq
8424
+ Shift index by desired number of periods with an optional time `freq`.
8425
+
8426
+ When `freq` is not passed, shift the index without realigning the data.
8427
+ If `freq` is passed (in this case, the index must be date or datetime,
8428
+ or it will raise a `NotImplementedError`), the index will be
8429
+ increased using the periods and the `freq`.
8425
8430
8426
8431
Parameters
8427
8432
----------
8428
8433
periods : int
8429
- Number of periods to move, can be positive or negative.
8430
- freq : DateOffset, timedelta, or time rule string, optional
8431
- Increment to use from the tseries module or time rule (e.g. 'EOM').
8432
- See Notes.
8433
- axis : %(axes_single_arg)s
8434
+ Number of periods to shift. Can be positive or negative.
8435
+ freq : DateOffset, tseries.offsets, timedelta, or str, optional
8436
+ Offset to use from the tseries module or time rule (e.g. 'EOM').
8437
+ If `freq` is specified then the index values are shifted but the
8438
+ data is not realigned. That is, use `freq` if you would like to
8439
+ extend the index when shifting and preserve the original data.
8440
+ axis : {0 or 'index', 1 or 'columns', None}, default None
8441
+ Shift direction.
8442
+
8443
+ Returns
8444
+ -------
8445
+ %(klass)s
8446
+ Copy of input object, shifted.
8434
8447
8435
8448
See Also
8436
8449
--------
8437
8450
Index.shift : Shift values of Index.
8438
8451
DatetimeIndex.shift : Shift values of DatetimeIndex.
8439
8452
PeriodIndex.shift : Shift values of PeriodIndex.
8453
+ tshift : Shift the time index, using the index's frequency if
8454
+ available.
8440
8455
8441
- Notes
8442
- -----
8443
- If freq is specified then the index values are shifted but the data
8444
- is not realigned. That is, use freq if you would like to extend the
8445
- index when shifting and preserve the original data.
8446
-
8447
- Returns
8448
- -------
8449
- shifted : %(klass)s
8456
+ Examples
8457
+ --------
8458
+ >>> df = pd.DataFrame({'Col1': [10, 20, 15, 30, 45],
8459
+ ... 'Col2': [13, 23, 18, 33, 48],
8460
+ ... 'Col3': [17, 27, 22, 37, 52]})
8461
+
8462
+ >>> df.shift(periods=3)
8463
+ Col1 Col2 Col3
8464
+ 0 NaN NaN NaN
8465
+ 1 NaN NaN NaN
8466
+ 2 NaN NaN NaN
8467
+ 3 10.0 13.0 17.0
8468
+ 4 20.0 23.0 27.0
8469
+
8470
+ >>> df.shift(periods=1, axis='columns')
8471
+ Col1 Col2 Col3
8472
+ 0 NaN 10.0 13.0
8473
+ 1 NaN 20.0 23.0
8474
+ 2 NaN 15.0 18.0
8475
+ 3 NaN 30.0 33.0
8476
+ 4 NaN 45.0 48.0
8450
8477
""" )
8451
8478
8452
8479
@Appender (_shared_docs ['shift' ] % _shared_doc_kwargs )
0 commit comments