conditional replace based off prior value in same column of pandas dataframe python

后端 未结 2 1854
你的背包
你的背包 2021-01-16 06:51

Feel like I\'ve looked just about everywhere and I know its probably something very simple. I\'m working with a pandas dataframe and looking to fill/replace data in one of

2条回答
  •  滥情空心
    2021-01-16 06:57

    using Where

    df['B'] = df.A[0:len(df.A)-1].where((df.A==0 ) & (df.B.shift(-1)==-1),-1)
    df['B'] = df['B'].fillna(df.A)
    

提交回复
热议问题