For example, I want get right from left DataFrame like on picture (move column B on 2 steps down):
PS. "Na" is not necessary, it can be any controlled value like null, zero or empty string.
Data Science Stack Exchange is a question and answer site for Data science professionals, Machine Learning specialists, and those interested in learning more about the field. It only takes a minute to sign up.
Sign up to join this communityYou 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.