给定数据框
df = pd.DataFrame({'word1': ['elvis', 'lease', 'admirer'], 'word2': ['lives', 'sale', 'married']})
如何添加第三列,根据同一行中的两个单词是否是字谜词返回 True 或 False?
我已经编写了这个函数,当我将它应用于 df.
def anagram(word1, word2):
word1_lst = [l for l in word1]
word2_lst = [i for i in word2]
return sorted(word1_lst) == sorted(word2_lst)
df['Anagram'] = df.apply(anagram(df['word1'], df['word2']), axis = 1)
类型错误:“bool”对象不可调用
汪汪一只猫
繁星淼淼
相关分类