@@ -7606,28 +7606,31 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
7606
7606
Shift index by desired number of periods with an optional time `freq`.
7607
7607
7608
7608
When `freq` is not passed, shift the index without realigning the data.
7609
- If `freq` is passed (in this case, the index must be date or datetime),
7610
- the index will be increased using the periods and the `freq`.
7609
+ If `freq` is passed (in this case, the index must be date or datetime,
7610
+ or it will raises a `NotImplementedError`), the index will be
7611
+ increased using the periods and the `freq`.
7611
7612
7612
7613
Parameters
7613
7614
----------
7614
7615
periods : int
7615
7616
Number of periods to shift; can be positive or negative.
7616
7617
freq : DateOffset, timedelta, or time rule string, optional
7617
7618
Increment to use from the tseries module or time rule (e.g. 'EOM').
7618
- See Notes.
7619
+ If `freq` is specified then the index values are shifted but the
7620
+ data is not realigned. That is, use `freq` if you would like to
7621
+ extend the index when shifting and preserve the original data.
7619
7622
axis : {0 or ‘index’, 1 or ‘columns’, None}, default None
7620
7623
Shift direction.
7621
7624
7622
- Notes
7623
- -----
7624
- If `freq` is specified then the index values are shifted but the data
7625
- is not realigned. That is, use `freq` if you would like to extend the
7626
- index when shifting and preserve the original data.
7627
-
7628
7625
Returns
7629
7626
-------
7630
- shifted : %(klass)s
7627
+ %(klass)s
7628
+ Copy of input object, shifted.
7629
+
7630
+ See Also
7631
+ --------
7632
+ tshift : Shift the time index, using the index’s frequency if
7633
+ available.
7631
7634
7632
7635
Examples
7633
7636
--------
@@ -7651,42 +7654,42 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
7651
7654
3 NaN 30.0 33.0
7652
7655
4 NaN 45.0 48.0
7653
7656
7654
- >>> import datetime
7655
- >>> names = ['João', 'Maria', 'Emanuel', 'Jussara', 'José']
7656
- >>> dates = [datetime.datetime(2018, 3, 1, 11, 15),
7657
- ... datetime.datetime(2018, 3, 5, 11, 15),
7658
- ... datetime.datetime(2018, 3, 10, 11, 15),
7659
- ... datetime.datetime(2018, 3, 15, 11, 15),
7660
- ... datetime.datetime(2018, 3, 20, 11, 15)]
7657
+ **freq parameter**
7658
+
7659
+ When using the freq parameter with a :class:pandas.DateTimeIndex
7660
+ the index values are shifted but the data is not realigned.
7661
+
7662
+ >>> names = ['Joaquim', 'Maria', 'Emanuel', 'Jussara', 'Geraldo']
7663
+ >>> dates = pd.date_range(start='2018-03-05 11:15:00',
7664
+ ... freq='5D', periods=5)
7661
7665
>>> df = pd.DataFrame(data={'names': names}, index=dates)
7662
7666
>>> df
7663
7667
names
7664
- 2018-03-01 11:15:00 João
7665
- 2018-03-05 11:15:00 Maria
7666
- 2018-03-10 11:15:00 Emanuel
7667
- 2018-03-15 11:15:00 Jussara
7668
- 2018-03-20 11:15:00 José
7668
+ 2018-03-05 11:15:00 Joaquim
7669
+ 2018-03-10 11:15:00 Maria
7670
+ 2018-03-15 11:15:00 Emanuel
7671
+ 2018-03-20 11:15:00 Jussara
7672
+ 2018-03-25 11:15:00 Geraldo
7673
+
7674
+ Shift the index by 2 days (offset-alias 'D').
7669
7675
7670
7676
>>> df.shift(periods=2, freq='D')
7671
7677
names
7672
- 2018-03-03 11:15:00 João
7673
- 2018-03-07 11:15:00 Maria
7674
- 2018-03-12 11:15:00 Emanuel
7675
- 2018-03-17 11:15:00 Jussara
7676
- 2018-03-22 11:15:00 José
7678
+ 2018-03-07 11:15:00 Joaquim
7679
+ 2018-03-12 11:15:00 Maria
7680
+ 2018-03-17 11:15:00 Emanuel
7681
+ 2018-03-22 11:15:00 Jussara
7682
+ 2018-03-27 11:15:00 Geraldo
7683
+
7684
+ Shift the index by 75 minutes (offset-alias 'min').
7677
7685
7678
7686
>>> df.shift(periods=75, freq='min')
7679
7687
names
7680
- 2018-03-01 12:30:00 João
7681
- 2018-03-05 12:30:00 Maria
7682
- 2018-03-10 12:30:00 Emanuel
7683
- 2018-03-15 12:30:00 Jussara
7684
- 2018-03-20 12:30:00 José
7685
-
7686
- See Also
7687
- --------
7688
- tshift : Shift the time index, using the index’s frequency if
7689
- available.
7688
+ 2018-03-05 12:30:00 Joaquim
7689
+ 2018-03-10 12:30:00 Maria
7690
+ 2018-03-15 12:30:00 Emanuel
7691
+ 2018-03-20 12:30:00 Jussara
7692
+ 2018-03-25 12:30:00 Geraldo
7690
7693
""" )
7691
7694
7692
7695
@Appender (_shared_docs ['shift' ] % _shared_doc_kwargs )
0 commit comments