我正在寻找一种解决方案,以显示两个列之间差异的位置。
Input:
df=pd.DataFrame({'A':['this is my favourite one','my dog is the best'],
'B':['now is my favourite one','my doggy is the worst']})
expected output:
[A-B],[B-A]
0:4 ,0:3 #'this','now'
3:6 ,3:8 #'dog','doggy'
14:18,16:21 #'best','worst'
目前我只有一种方法来搜索差异(但不起作用,不知道为什么)
df['A-B']=df.apply(lambda x: x['A'].replace(x['B'], "").strip(),axis=1)
df['B-A']=df.apply(lambda x: x['B'].replace(x['A'], "").strip(),axis=1)