Python 删除系列中的标点符号
这是我的Python 删除系列中的标点符号,python,pandas,nlp,data-cleaning,Python,Pandas,Nlp,Data Cleaning,这是我的系列,已标记并删除了停止词: 0 [laptop, sits, 4, stars, similarly, priced, co... 1 [ordered, monitor, wanted, makeshift, area, po... 2 [monitor, great, deal, price, size, ., use, of... 3 [bought, height, adjustment, ., swivel, abili
系列
,已标记并删除了停止词:
0 [laptop, sits, 4, stars, similarly, priced, co...
1 [ordered, monitor, wanted, makeshift, area, po...
2 [monitor, great, deal, price, size, ., use, of...
3 [bought, height, adjustment, ., swivel, abilit...
4 [worked, month, died, ., 5, calls, hp, support...
...
30618 [great, deal]
30619 [pour, le, travail]
30620 [business, use]
30621 [good, size]
30622 [pour, mon, ordinateur.plus, grande, image.vra...
Name: text_body, Length: 30623, dtype: object
我想删除上述系列中的标点符号。我试过这样的东西
filtered_text = re.sub(r'[^\w\s]','',str(series))
结果显示为字符串
我有两个问题
过滤的\u文本
字符串转换回列表或序列理想情况下,您应该从以下序列中删除
标点符号
:
filtered_text = s.str.replace('[^\w\s]','')
其中s
是您的系列
说明:
首先通过.str
将序列转换为字符串,然后应用替换
正则表达式。
现在您不必担心再次将其转换回
系列。我尝试了您的方法。而且,filtered_text
结果似乎充满了NaN
值。我有办法解决这个问题吗?无论如何,谢谢你的回答,非常感谢。你能在结果
变得NaN
的地方分享更多数据吗?如果问题得到解决,请单击我的答案旁边的勾选标记
,接受我的答案。