[英]Iterate through a list of strings from a column in dataframe python
I have a pandas dataframe containing a list of words in the 'Message' column.我有一个 pandas dataframe 包含“消息”列中的单词列表。 How do i iterate through the list of strings from the column to apply a function that i created to correct the spelling?
我如何遍历列中的字符串列表以应用我创建的 function 以更正拼写?
I already have the function for the correction ready.我已经准备好了 function 以进行更正。
def correct_spelling(data):
w = Word(data)
correct_word = (w.correct())
return correct_word
df['Message'] = correct_spelling(df['Message'])
INITIAL DATAFRAME初始 DATAFRAME
S/No Month Message S/No 月份消息
0 June [hey, howw, are, yyou, doing, today, i...] 6 月 0 日 [嘿,哇,是,你,在做,今天,我...]
1 August [sally, thinks, that, this, jobb, is, easyy...] 8 月 1 日 [莎莉,认为,那个,这个,乔布,是,很容易......]
2 February [trry, to, buiy, him, a, neow, watch... ] 2 月 2 日 [try, to, buy, him, a, new, watch...]
3 December [i, have, twp, much, taime, on, my, hand... ] 12 月 3 日 [i, have, twp, much, taime, on, my, hand...]
FINAL DATAFRAME最终 DATAFRAME
S/No Month Message S/No 月份消息
0 June [hey, how, are, you, doing, today, i...] 6 月 0 日 [嘿,你怎么样,今天,我……]
1 August [sally, thinks, that, this, job, is, easy...] 8 月 1 日 [莎莉,认为,那,这,工作,很简单……]
2 February [try, to, buy, him, a, new, watch... ] 2 月 2 日 [try, to, buy, him, a, new, watch...]
3 December [i, have, two, much, time, on, my, hand... ] 12 月 3 日 [i, have, two, much, time, on, my, hand...]
If need processing each word separately use:如果需要单独处理每个单词,请使用:
df['Message'] = df['Message'].apply(lambda x: [correct_spelling(y) for y in x])
If possible pass list:如果可能通过列表:
df['Message'] = df['Message'].apply(correct_spelling)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.