繁体   English   中英

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

[英]Iterate through a list of strings from a column in dataframe python

我有一个 pandas dataframe 包含“消息”列中的单词列表。 我如何遍历列中的字符串列表以应用我创建的 function 以更正拼写?

我已经准备好了 function 以进行更正。

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



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

初始 DATAFRAME

S/No 月份消息

6 月 0 日 [嘿,哇,是,你,在做,今天,我...]

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

2 月 2 日 [try, to, buy, him, a, new, watch...]

12 月 3 日 [i, have, twp, much, taime, on, my, hand...]

最终 DATAFRAME

S/No 月份消息

6 月 0 日 [嘿,你怎么样,今天,我……]

8 月 1 日 [莎莉,认为,那,这,工作,很简单……]

2 月 2 日 [try, to, buy, him, a, new, watch...]

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM