Ваш вопрос довольно нетривиален, и, как упоминалось в комментариях, вероятно, лучше использовать difflib.Sequencematcher.get_matching_blocks
для этого, но я не смог заставить его работать. Итак, вот рабочее решение, которое не будет работать с точки зрения скорости, но получит результат.
Сначала мы получаем разницу в словах, затем мы находим начальную + конечную позицию в каждом столбце:
def get_diff_words(col1, col2):
diff_words = [[w1, w2] for w1, w2 in zip(col1, col2) if w1 != w2]
return diff_words
df['diff_words'] = df.apply(lambda x: get_diff_words(x['A'].split(), x['B'].split()), axis=1)
df['pos_A'] = df.apply(lambda x: [f'{x["A"].find(word[0])}:{x["A"].find(word[0])+len(word[0])}' for word in x['diff_words']], axis=1)
df['pos_B'] = df.apply(lambda x: [f'{x["B"].find(word[1])}:{x["B"].find(word[1])+len(word[1])}' for word in x['diff_words']], axis=1)
Выход
A B diff_words pos_A pos_B
0 this is my favourite one now is my favourite one [[this, now]] [0:4] [0:3]
1 my dog is the best my doggy is the worst [[dog, doggy], [best, worst]] [3:6, 14:18] [3:8, 16:21]