Python | Pandas dataframe.slice_shift() Last Updated : 23 Nov, 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 dataframe.slice_shift() function is Equivalent to shift without copying data. The shifted data will not include the dropped periods and the shifted axis will be smaller than the original. This function simply drops the specified number of periods over the given axis in a specified direction. Syntax: DataFrame.slice_shift(periods=1, axis=0) Parameters : periods : Number of periods to move, can be positive or negative Return : shifted : same type as caller Example #1: Use slice_shift() function to shift the index axis by 2 periods in a time-series data Python3 # importing pandas as pd import pandas as pd # Creating row index values for dataframe # We have taken time frequency to be of 12 hours interval # Generating five index value using "period = 5" parameter ind = pd.date_range('01/01/2000', periods = 5, freq ='12H') # Creating a dataframe with 4 columns # using "ind" as the index for our dataframe df = pd.DataFrame({"A":[1, 2, 3, 4, 5], "B":[10, 20, 30, 40, 50], "C":[11, 22, 33, 44, 55], "D":[12, 24, 51, 36, 2]}, index = ind) # Print the dataframe df Let's use the dataframe.slice_shift() function to shift the index axis by 2 periods in positive direction Python3 1== # shift index axis by two # periods in positive direction # axis = 0 is set by default df.slice_shift(2, axis = 0) Output : Notice the index labels, first two labels are dropped but the data has been shifted by two periods in the positive direction. We can also shift the index axis in negative direction by some periods Python3 1== # shift index axis by two # periods in negative direction # axis = 0 is set by default df.slice_shift(-2, axis = 0) Output : Notice in the output, the data points has been shifted in the negative direction (i.e. upward) by 2 periods and the last two index labels has been removed. Example #2: Use slice_shift() function to shift the column axis by 2 periods in a time-series data Python3 # importing pandas as pd import pandas as pd # Creating row index values for our data frame # Taken time frequency to be of 12 hours interval # Generating five index value using "period = 5" parameter ind = pd.date_range('01/01/2000', periods = 5, freq ='12H') # Creating a dataframe with 4 columns # using "ind" as the index for our dataframe df = pd.DataFrame({"A":[1, 2, 3, 4, 5], "B":[10, 20, 30, 40, 50], "C":[11, 22, 33, 44, 55], "D":[12, 24, 51, 36, 2]}, index = ind) # shift column axis by two periods in positive direction df.slice_shift(2, axis = 1) Output : In the output, we can see the first two column labels are removed and the data point along the column axis has been shifted by 2 periods in the positive direction. We can also shift the column axis in negative direction by some periods Python3 1== # shift column axis by two periods in negative direction df.slice_shift(-2, axis = 0) Output : In the output, we can see the last two column labels are removed and the data point along the column axis has been shifted by 2 periods in the negative direction (i.e. left). Comment More infoAdvertise with us Next Article Python | Pandas dataframe.slice_shift() S Shubham__Ranjan Follow Improve Article Tags : Technical Scripter Python Python-pandas Python pandas-dataFrame Pandas-DataFrame-Methods +1 More Practice Tags : python Similar Reads 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 DataFrame.tshift Pandas DataFrame is a two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Arithmetic operations align on both row and column labels. It can be thought of as a dict-like container for Series objects. This is the primary data structure o 3 min read Python | Pandas DataFrame.truncate Pandas DataFrame is a two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Arithmetic operations align on both row and column labels. It can be thought of as a dict-like container for Series objects. This is the primary data structure o 3 min read Python | Pandas DataFrame.values Pandas DataFrame is a two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Arithmetic operations align on both row and column labels. It can be thought of as a dict-like container for Series objects. This is the primary data structure o 2 min read Python | Pandas dataframe.rfloordiv() 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.rfloordiv() function is used for Integer division of dataframe and ot 3 min read Python | Pandas dataframe.swapaxes() 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.swapaxes() function interchange axes and swap values axes appropriate 2 min read Python | Pandas DataFrame.transform Pandas DataFrame is a two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Arithmetic operations align on both row and column labels. It can be thought of as a dict-like container for Series objects. This is the primary data structure o 3 min read Python | Pandas Series.slice_shift() Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Pandas Series.slice_shift() function is equ 2 min read Python | Pandas DataFrame.ix[ ] 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.ix[ ] is both Label and Integer based slicing technique. Besides pure 2 min read Python | Pandas DataFrame.to_records Pandas DataFrame is a two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Arithmetic operations align on both row and column labels. It can be thought of as a dict-like container for Series objects. This is the primary data structure o 2 min read Like