Pandas: Conditionally replace values based on other columns values

前端 未结 4 758
别那么骄傲
别那么骄傲 2021-02-06 11:52

I have a dataframe (df) that looks like this:

                    environment     event   
time                    
2017-04-28 13:08:22     NaN         add_rd  
         


        
4条回答
  •  攒了一身酷
    2021-02-06 12:04

    You could consider using where:

    df.environment.where((~df.environment.isnull()) & (df.event != 'add_rd'),
                         'RD', inplace=True)
    

    If the condition is not met, the values is replaced by the second element.

提交回复
热议问题