How to conditionally update DataFrame column in Pandas

前端 未结 3 1794
挽巷
挽巷 2020-12-01 02:28

With this DataFrame, how can I conditionally set rating to 0 when line_race is equal to zero?

    line_track  line_race  rating fo         


        
3条回答
  •  鱼传尺愫
    2020-12-01 03:25

    Use numpy.where to say if ColumnA = x then ColumnB = y else ColumnB = ColumnB:

    df['rating'] = np.where(df['line_race']==0, 0, df['rating'])
    

提交回复
热议问题