我的df中有一列如下所示:
Service
DoorDash, Grubhub / Seamless, UberEats, Postmates
DoorDash, UberEats, Caviar, Tock
DoorDash
None
Caviar, Tock
None
Tock
DoorDash, Grubhub / Seamless, UberEats, Postmates
Grubhub / Seamless, UberEats
是否有一种有效的方式可以为每个服务创建一个新列,如果服务列中存在该服务,则新列中的值将是True或False的布尔值
如果我有一个服务名称列表,例如:
DoorDash,Grubhub/无缝,优步,鱼子酱,邮递,JustEat,Deliverio,Foodora,Grab,Talabat
我想为上面列表中的每个名称创建一列,并根据服务列中是否存在该服务,将其值设置为True或False
预期输出:
Service | DoorDash | Grubhub / Seamless | UberEats| Caviar | Postmates | JustEat | Deliveroo | Foodora | Grab | Talabat | Tock
DoorDash, Grubhub / Seamless, UberEats, Postmates True True True False True False False False False False False
DoorDash, UberEats, Caviar, Tock True False True True False False False False False False True
DoorDash True False False False False False False False False False False
None False False False False False False False False False False False
Caviar, Tock False False False True False False False False False False True
None False False False False False False False False False False False
Tock False False False False False False False False False False True
DoorDash, Grubhub / Seamless, UberEats, Postmates True True True False True False False False False False False
Grubhub / Seamless, UberEats False True True False False False False False False False False
谢谢你的关注
将^{} 与convert to boolean一起使用,按^{} 中的列表添加缺少的值,最后添加到原始值:
相关问题 更多 >
编程相关推荐