I have a pandas dataframe containing a list of words in the 'Message' column. How do i iterate through the list of strings from the column to apply a function that i created to correct the spelling?
I already have the function for the correction ready.
def correct_spelling(data):
w = Word(data)
correct_word = (w.correct())
return correct_word
df['Message'] = correct_spelling(df['Message'])
INITIAL DATAFRAME
S/No Month Message
0 June [hey, howw, are, yyou, doing, today, i...]
1 August [sally, thinks, that, this, jobb, is, easyy...]
2 February [trry, to, buiy, him, a, neow, watch... ]
3 December [i, have, twp, much, taime, on, my, hand... ]
FINAL DATAFRAME
S/No Month Message
0 June [hey, how, are, you, doing, today, i...]
1 August [sally, thinks, that, this, job, is, easy...]
2 February [try, to, buy, him, a, new, watch... ]
3 December [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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.