Python | Pandas Index.shift() Last Updated : 18 Dec, 2018 Comments Improve Suggest changes Like Article Like Report Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.shift() function shift index by desired number of time frequency increments. This method is for shifting the values of datetime-like indexes by a specified time increment a given number of times. This method is only implemented for datetime-like index classes, i.e., DatetimeIndex, PeriodIndex and TimedeltaIndex. Syntax: Index.shift(periods=1, freq=None) Parameters : periods : Number of periods (or increments) to shift by, can be positive or negative. freq : [pandas.DateOffset, pandas.Timedelta or string, optional] Frequency increment to shift by. If None, the index is shifted by its own freq attribute. Offset aliases are valid strings, e.g., ‘D’, ‘W’, ‘M’ etc Returns : shifted index Example #1: Use Index.shift() function to shift a time-series data by certain duration. Python3 # importing pandas as pd import pandas as pd # Creating the index idx = pd.date_range('1 / 1/2018', periods = 3, freq ='MS') # Print the index idx Output : Now we would shift the index by 5 Days. Python3 1== # shifting the index by 5 days idx.shift(5, freq ='D') Output : As we can see in the output, the dates have been shifted forward by 5 Days. Example #2: Use Index.shift() function shift the date-time based index. Python3 # importing pandas as pd import pandas as pd # Creating the index idx = pd.date_range('1 / 1/2018', periods = 3, freq ='MS') # Print the index idx Output : Now we would shift the index by 5 Months. Python3 1== # shifting the index by 5 Months idx.shift(5, freq ='MS') Output : As we can see in the output, the date has been shifted forward by 5 months. Comment More infoAdvertise with us Next Article Python | Pandas Index.shift() S Shubham__Ranjan Follow Improve Article Tags : Technical Scripter Python Python-pandas Python pandas-indexing Practice Tags : python Similar Reads Python | Pandas Index.size Pandas Index is an immutable ndarray implementing an ordered, sliceable set. It is the basic object which stores the axis labels for all pandas objects. Pandas Index.size attribute return the number of elements in the underlying data of the given Index object. Syntax: Index.size Parameter : None Ret 2 min read Python | Pandas Index.shape Pandas Index is an immutable ndarray implementing an ordered, sliceable set. It is the basic object which stores the axis labels for all pandas objects. Pandas Index.shape attribute return a tuple of the shape of the underlying data in the given Index object. Syntax: Index.shape Parameter : None Ret 2 min read Python | Pandas Index.tolist() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.tolist() function return a list of the values. These are each a scalar ty 1 min read Python | Pandas Index.to_series() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.to_series() function create a Series with both index and values equal to 2 min read Python | Pandas Index.strides Pandas Index is an immutable ndarray implementing an ordered, sliceable set. It is the basic object which stores the axis labels for all pandas objects. Pandas Index.strides attribute return the strides of the underlying data of the given Index object. It basically return a tuple of bytes to step in 2 min read Python | Pandas Index.where Pandas Index is an immutable ndarray implementing an ordered, sliceable set. It is the basic object which stores the axis labels for all pandas objects. Pandas Index.where function return an Index of same shape as self and whose corresponding entries are from self where cond is True and otherwise ar 2 min read Python | Pandas Index.values Pandas Index is an immutable ndarray implementing an ordered, sliceable set. It is the basic object which stores the axis labels for all pandas objects. Pandas Index.values attribute return an array representing the data in the given Index object. Syntax: Index.values Parameter : None Returns : an a 2 min read Python | Pandas dataframe.shift() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas dataframe.shift() function Shift index by the desired number of periods with an 5 min read Python | Pandas Index.searchsorted() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.Pandas Index.searchsorted() function find indices where elements should be inserted to 2 min read Python | Pandas Index.dtype_str Pandas Index is an immutable ndarray implementing an ordered, sliceable set. It is the basic object which stores the axis labels for all pandas objects. Pandas Index.dtype_str attribute return the data type (dtype) of the underlying data of the given Index object as a string. Syntax: Index.dtype_str 2 min read Like