我的目标是创建一个基于多个字符串匹配的新列。这个新列将为事件列上的每个匹配返回1。
Date Event
0 2022-11-01 Breakfast
1 2022-11-01 Breakfast
2 2022-11-01 Lunch
3 2022-11-02 Breakfast
4 2022-11-02 Lunch
之后
Date Event Breakfast Lunch
0 2022-11-01 Breakfast 1 null
1 2022-11-01 Breakfast 1 null
2 2022-11-01 Lunch null 1
3 2022-11-02 Breakfast 1 null
4 2022-11-02 Lunch null 1
3条答案
按热度按时间polkgigr1#
您可以使用
pd.get_dummies
执行以下任务:图纸:
如果你想要
None
而不是0
:图纸:
laximzn52#
您也可以使用Map功能:
shyt4zoc3#
这很容易。
溶液
输出