Skip to content
Advertisement

How to update a value of a cell of a dataframe using the value of two cells below?

I have the following dataframe (created for an example):

JavaScript

Assuming that this is a long dataframe, whenever there is a value of 2 in row B, I need to replace that value with the value that is two cells below that.

I tried:

JavaScript

But I get:

JavaScript

And I need:

JavaScript

Does anyone have suggestions for leaving rows that do not equal ‘2’ unchanged?

Advertisement

Answer

Then we just need to assign it with shift

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement