删除除逗号以外的所有字符和数字
我正在尝试从数据框列中的字符串中删除所有字符,但请保留逗号,但它仍然可以删除包括逗号在内的所有内容。
我知道之前已经问过这个问题,但我尝试了很多答案,并且都删除了逗号。
df[new_text_field_name] = df[new_text_field_name].apply(lambda elem: re.sub(r"(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)|^rt|http.+?", "", str(elem)))
示例文本:
'100%聚酯,纸板(最小30%再生),100%聚丙烯',
'polyerter,纸板,纸板,聚丙烯',,
I am trying to remove all the characters from string in the DataFrame column but keep the comma but it still removes everything including the comma.
I know the question has been asked before but I tried many answers and all remove the comma as well.
df[new_text_field_name] = df[new_text_field_name].apply(lambda elem: re.sub(r"(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)|^rt|http.+?", "", str(elem)))
sample text:
'100 % polyester, Paperboard (min. 30% recycled), 100% polypropylene',
the required output:
' polyester, Paperboard , polypropylene',
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能的解决方案如下:
返回
Possible solution is the following:
Returns
targin.isdigit()和targin.isletter()函数可用于识别其是数字还是字符。
Character.isDigit() and Character.isLetter() functions can be used to identify whether it is number or character.