Create Column with ELIF in Pandas

前端 未结 4 949
轻奢々
轻奢々 2020-11-29 01:50

Question

I am having trouble figuring out how to create new DataFrame column based on the values in two other columns. I need to use if/elif/else l

4条回答
  •  悲哀的现实
    2020-11-29 02:10

    I tried the following and the result was much faster. Hope it's helpful for others.

    df['combo'] = 'other'
    df.loc[df['mobile'] == 'mobile', 'combo'] = 'mobile'
    df.loc[df['tablet'] == 'tablet', 'combo'] = 'tablet'
    

提交回复
热议问题