@@ -2211,13 +2211,55 @@ def sortlevel(self, level=None, ascending=True, sort_remaining=None):
22112211 return self .sort_values (return_indexer = True , ascending = ascending )
22122212
22132213 def shift (self , periods = 1 , freq = None ):
2214- """
2215- Shift Index containing datetime objects by input number of periods and
2216- DateOffset
2214+ """Shift index by desired number of time frequency increments.
2215+
2216+ This method is for shifting the values of datetime-like indexes
2217+ by a specified time increment a given number of times.
2218+
2219+ Parameters
2220+ ----------
2221+ periods : int
2222+ Number of periods (or increments) to shift by,
2223+ can be positive or negative (default is 1).
2224+ freq : pandas.DateOffset, pandas.Timedelta or string
2225+ Frequency increment to shift by (default is None).
2226+ If None, the index is shifted by its own `freq` attribute.
2227+ Offset aliases are valid strings, e.g., 'D', 'W', 'M' etc.
22172228
22182229 Returns
22192230 -------
2220- shifted : Index
2231+ pandas.Index
2232+ shifted index
2233+
2234+ Examples
2235+ --------
2236+ Put the first 5 month starts of 2011 into an index.
2237+
2238+ >>> month_starts = pd.date_range('1/1/2011', periods=5, freq='MS')
2239+ >>> month_starts
2240+ DatetimeIndex(['2011-01-01', '2011-02-01', '2011-03-01', '2011-04-01',
2241+ '2011-05-01'],
2242+ dtype='datetime64[ns]', freq='MS')
2243+
2244+ Shift the index by 10 days.
2245+
2246+ >>> month_starts.shift(10, freq='D')
2247+ DatetimeIndex(['2011-01-11', '2011-02-11', '2011-03-11', '2011-04-11',
2248+ '2011-05-11'],
2249+ dtype='datetime64[ns]', freq=None)
2250+
2251+ The default value of `freq` is the `freq` attribute of the index,
2252+ which is 'MS' (month start) in this example.
2253+
2254+ >>> month_starts.shift(10)
2255+ DatetimeIndex(['2011-11-01', '2011-12-01', '2012-01-01', '2012-02-01',
2256+ '2012-03-01'],
2257+ dtype='datetime64[ns]', freq='MS')
2258+
2259+ Notes
2260+ -----
2261+ This method is only implemented for datetime-like index classes,
2262+ i.e., DatetimeIndex, PeriodIndex and TimedeltaIndex.
22212263 """
22222264 raise NotImplementedError ("Not supported for type %s" %
22232265 type (self ).__name__ )
0 commit comments