簡體   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