简体   繁体   English

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

[英]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.

相关问题 Python-遍历列表字符串列表 - Python - Iterate through list of list strings 遍历 dataframe 和字典以更新 dataframe 中的值以匹配字符串与 python - iterate through dataframe and dictionary to update values in dataframe for matching strings with python 遍历 dataframe 行并替换特定列中的字符串元素 - Iterate through dataframe rows and replace elements of strings within a specific column Python - 遍历字符串列表并组合部分匹配字符串 - Python - Iterate through a list of strings and group partial matching strings 从Python Dataframe列中提取字符串的唯一列表 - Extracting unique list of strings from Python Dataframe column Python - 从列表中搜索并显示 dataframe 的列中的字符串 - Python - Search and present strings within a column in dataframe from a list 如何从 python pandas dataframe 的列中的列表中提取字符串? - How to extract strings from a list in a column in a python pandas dataframe? 如何从 python pandas 数据框中的列中的列表中提取关键字(字符串)? - How to extract keywords (strings) from a list in a column in a python pandas dataframe? Python:如何遍历数据框中的列范围,检查特定值并将列名存储在列表中 - Python: How to iterate through a range of columns in a dataframe, check for specific values and store column name in a list Python 通过 dataframe 内的字符串列表连接 - Python concat through a list of strings inside a dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM