np.where() do nothing if condition fails

前端 未结 2 621
不思量自难忘°
不思量自难忘° 2021-01-06 05:48

I have a sample from my dataframe:

       Created      Insert Time   MatchKey              In Previous    New Type
18593  2016-08-12   2018-02-19    LXGS0903         


        
2条回答
  •  猫巷女王i
    2021-01-06 06:21

    Just return the column instead of pass this is the same as doing nothing when the condition is False:

    current['New Type'] = np.where(current['In Previous']=='Yes','In Previous',current['New Type'] )
    

    Or you can just mask those rows:

    current['New Type'] = current.loc[current['In Previous']=='Yes', 'In Previous']
    

提交回复
热议问题