how to compare two columns in pandas to make a third column ?

前端 未结 3 1185
甜味超标
甜味超标 2020-12-17 17:22

i have two columns age and sex in a pandas dataframe

sex = [\'m\', \'f\' , \'m\', \'f\', \'f\', \'f\', \'f\']
age = [16 ,  15 , 14 , 9  , 8   , 2   , 56 ]
<         


        
3条回答
  •  一向
    一向 (楼主)
    2020-12-17 17:30

    You could use pandas.DataFrame.where. For example

    child.where(age<=9, sex)
    

提交回复
热议问题