Home > Software design >  copy value from one column to another if condition is met in pandas
copy value from one column to another if condition is met in pandas

Time:02-14

I have a dataframe:

df =

col1 Aciton1
1 A
2 B
3 C
1 C

I want to edit df, such that when the value of col1 is bigger than 1 , take the value from Action1.

So I will get:

col1 Aciton1 Previous_Aciton
1 A Initial Action
2 B A
3 C B
1 C Initial Action

CodePudding user response:

If there are no negative and 0 values and each group starting by 1 is possible use enter image description here

the result:

enter image description here

  • Related