For example, I want get right from left DataFrame like on picture (move column B on 2 steps down):

Pandas Example

PS. "Na" is not necessary, it can be any controlled value like null, zero or empty string.


1 Answer 1


You can use the .shift method for this:

df["B"] = df["B"].shift(2)

The value used for the first two rows (NA or something else) can be controlled using the fill_value argument.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.