Skip to content
Advertisement

Creating a column with conditions over multiple rows

I have the next DataFrame:

JavaScript

I need to create a column considering the variation on the other column.

Following this result:

Letter Number
a 1
a 0
a 0
a 0
b 1
b 0
b 0
c 1
c 0
a 1

Every time the letter change, I need to put a 1.

Advertisement

Answer

shift

I’m assuming that df is what OP provided

JavaScript

Then reasigned the first column to a series letter

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