在dataframe python中遍历列中的字符串列表

在dataframe python中遍历列中的字符串列表,python,pandas,dataframe,Python,Pandas,Dataframe,我有一个pandas数据框,其中包含“Message”列中的单词列表。如何迭代列中的字符串列表以应用我创建的函数来更正拼写 我已经准备好了校正功能 def correct_spelling(data): w = Word(data) correct_word = (w.correct()) return correct_word df['Message'] = correct_spelling(df['Message']) 初始数据帧 S/无月份信息 6月0日【嘿,你好,你在做什么,今

我有一个pandas数据框,其中包含“Message”列中的单词列表。如何迭代列中的字符串列表以应用我创建的函数来更正拼写

我已经准备好了校正功能

def correct_spelling(data):
w = Word(data) 
correct_word = (w.correct())
return correct_word



df['Message'] = correct_spelling(df['Message'])
初始数据帧

S/无月份信息

6月0日【嘿,你好,你在做什么,今天,我…】

8月1日[莎莉,认为,这个,乔布,很容易…]

2月2日[trry,to,buy,him,a,neow,watch…]

12月3日[我,有,twp,很多,泰姆,在我的手上…]

最终数据帧

S/无月份信息

6月0日[嘿,你好吗,你在做什么,今天,我…]

8月1日【莎莉认为,这项工作很简单……】

2月2日[尝试,购买,他,一个,新的,手表…]


12月3日[i,have,two,much,time,on,my,hand…]

如果需要单独处理每个单词,请使用:

df['Message'] = df['Message'].apply(lambda x: [correct_spelling(y) for y in x])
如有可能,通过列表:

df['Message'] = df['Message'].apply(correct_spelling)

df['Message']=df['Message'].apply(lambda x:correct_拼写(x))
?我收到了以下错误。TypeError:“in”需要字符串作为左操作数,而不是列表没有注意到消息是一个列表,
df['message']=df['message']。应用(lambda x:[纠正x中y的拼写(y))
,检查Jezrael答案