如何基于一个现有列插入值

时间:2018-11-01 22:17:22

标签: python pandas numpy

我正在尝试根据另一列中的值填写。请查看下面的脚本,让我知道如何避免最后一行覆盖之前的语句。非常感谢您的提前帮助!

data_xls['New'] = np.where(data_xls['Old'].str.contains('(?:ps1)', regex=True), "Promoted Story", "" )
data_xls['New'] = np.where(data_xls['Old'].str.contains('(?:native)', regex=True), "Native","" )
data_xls['New'] = np.where(data_xls['Old'].str.contains('(?:email)', regex=True), "Email", "" )
data_xls['New'] = np.where(data_xls['Old'].str.contains('(?:email)', regex=True), "InMail","" )
data_xls['New'] = np.where(data_xls['Old'].str.contains('(?:sponsored)', regex=True), "Sponsored Content","")

谢谢你, 泰

0 个答案:

没有答案