Creating a new column based on the values of other columns

后端 未结 4 1187
孤街浪徒
孤街浪徒 2021-01-16 10:19

I wanted to create a \"High Value Indicator\" column, which says \"Y\" or \"N\" based on two different value columns. I want the new column to have a \"Y\" when Value_1 is >

4条回答
  •  感动是毒
    2021-01-16 10:58

    Try using .loc and .fillna

    df.loc[((df['Value_1'] > 1000) 
           |(df['Value_2'] > 15000)), 'High_Value_Ind'] = 'Y'
    
    df['High_Value_Ind'] = df['High_Value_Ind'].fillna('N')
    

提交回复
热议问题