![](/img/trans.png)
[英]How to iterate over words in line to change each next word in next loop/iteration
[英]Loop over each word in each row and remove words if in a list
我在 dataframe 中有以下一列(每一行都是一个人,每个单元格中都有一个标记化单词列表)。
Q395_R
[due, car, accident, year, ago, medical, condi...
[spending, time, loved, one, commute, able, co...
[initially, understanding, need, lockdown, ero...
[time, focus, exercise, le, sport, do, poured,..
[spending, time, family, realisation, need, ru...
我还有一个单词列表:
words395 = ['rising',
'accident',
'le',
'lasted',
'understanding',
'spending',
'adopted',
'raising',
'fabulous',
'loneliness',
'contract',....]
我想创建一个 function
我不确定如何通过每个人和单词创建两个循环到 go,有人可以帮忙吗?
预期结果:
Q395_R
[due, car, year, ago, medical, condi...
[time, loved, one, commute, able, co...
[initially, need, lockdown, ero...
[time, focus, exercise, sport, do, poured,..
[time, family, realisation, need, ru...
使用 lambda function 将值转换为列表到集合:
s = set(words395)
df['Q395_R'] = df['Q395_R'].apply(lambda x: [y for y in x if y not in s])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.