You can shift a pandas dataframe column backwards using the shift() method of pandas.
Here is how to shift a column named col_name in dataframe df backwards by n positions:
main.py46 chars2 lines
Where periods is the number of positions to shift backwards.
Here's an example:
main.py119 chars8 lines
This outputs:
main.py50 chars6 lines
As you can see, the B column has been shifted backwards by one position.
gistlibby LogSnag