【发布时间】:2020-04-08 11:00:23
【问题描述】:
我有如下熊猫数据框:
df = pd.DataFrame ({'col1': ['apple;orange;pear', 'grape;apple;kiwi;pear'], 'col2': ['apple', 'grape;kiwi']})
col1 col2
0 apple;orange;pear apple
1 grape;apple;kiwi;pear grape;kiwi
我需要如下数据:
col1 col2 col3
0 apple;orange;pear apple orange;pear
1 grape;apple;kiwi;pear grape;kiwi apple;pear
有人知道怎么做吗?谢谢。
在本例中,col2 grape;kiwi 的第二行,子字符串在 col1 grape;apple;kiwi;pear 的第二行的不同位置。
[How do I create a new column in pandas from the difference of two string columns? 在我的情况下不起作用。
【问题讨论】:
-
你尝试了什么?