在我的df文件中,下面的每个实体(Grubhub、Toasttab、Tenk)都有一列,并且每行的该列值中都显示“是”或“否”,
我有以下代码,例如:
df['Grubhub'] = df[['On GrubHub or Seamless?']].apply(lambda x: any(x == 'Yes'), axis = 1)
df['ToastTab'] = df[['On ToastTab?']].apply(lambda x: any(x == 'Yes'), axis = 1)
df['Tenk'] = df[['On Tenk?']].apply(lambda x: any(x == 'Yes'), axis = 1)
df['Udemy'] = df[['On Udmey?']].apply(lambda x: any(x == 'Yes'), axis = 1)
df['Postmates'] = df[['On Postmates?']].apply(lambda x: any(x == 'Yes'), axis = 1)
df['Doordash'] = df[['On DoorDash?']].apply(lambda x: any(x == 'Yes'), axis = 1)
df['Google'] = df[['On Goole?']].apply(lambda x: any(x == 'Yes'), axis = 1)
这为每个实体( Grubhub、Toasttab、Tenk )提供了一个新列,并且该列给出了 true 或 false 值,是否有一种更有效的方法可以在一行代码或函数中完成所有这些操作?感谢您提前的帮助
至尊宝的传说
相关分类