我有一个pandas数据框架,其中包含'Message'列中的单词列表。我如何从列中迭代字符串列表,以应用我创建的用于纠正拼写的函数?
我已经准备好了校正的功能。
def correct_spelling(data):
w = Word(data)
correct_word = (w.correct())
return correct_word
df['Message'] = correct_spelling(df['Message'])
初始DATAFRAME
S/No Month消息
0 June[嘿,你好,你好,你,今天怎么样,我…]
8月1日[莎莉,认为,这,工作,是,容易…]
2二月[try, to, buy, him, a, new, watch…])
[i, have, twp, much, time, on, my, hand…]) 最终DATAFRAME
S/No Month消息
0 June[嘿,你今天过得怎么样,我…]
1 August [sally,认为这份工作很容易…]
2二月[try, to, buy, him, a, new, watch…])
[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)