Creating a new column based on the values of other columns

后端 未结 4 1145
孤街浪徒
孤街浪徒 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 11:02

    Using map

    df['High Value Indicator'] =((df.Value_1 > 1000) | (df.Value_2 > 15000)).map({True:'Y',False:'N'})
    df
    Out[849]: 
       ID  Value_1  Value_2 High Value Indicator
    0   1      100     2500                    N
    1   2      250     6250                    N
    2   3      625    15625                    Y
    3   4     1500    37500                    Y
    4   5     3750    93750                    Y
    

提交回复
热议问题