Pandas DataFrame.shift()If you want to shift your column or subtract the column value with the previous row value from the DataFrame, you can do it by using the shift() function. It consists of a scalar parameter called period, which is responsible for showing the number of shifts to be made over the desired axis. It is also capable of dealing with time-series data. Syntax:Parameters:
ReturnsIt returns a shifted copy of DataFrame. Example1: The below example demonstrates the working of the shift(). Output a_data b_data c_data 0 NaN NaN NaN 1 NaN NaN NaN 2 45.0 26.0 22.0 3 28.0 37.0 19.0 4 39.0 41.0 11.0 Example2: The example shows how to fill the missing values in the DataFrame using the fill_value. Output a_data b_data c_data 0 70 70 45 1 70 70 28 2 70 70 39 3 70 70 32 4 70 70 18 Next TopicDataFrame.sort() |