[英]unwanted characters in pandas dataframe column
I want to delete "\n" and "[" characters from jobDescription column in dataframe.我想从 dataframe 的 jobDescription 列中删除“\n”和“[”字符。 I try this code.
我试试这段代码。 But it s not working
data['jobDescription'] = data['jobDescription'].str.replace(r'\n',' ', regex=True)
但它不起作用
data['jobDescription'] = data['jobDescription'].str.replace(r'\n',' ', regex=True)
you can see the df in the picture below;您可以在下图中看到 df;
how do i solve this problem?我该如何解决这个问题? Thanks.
谢谢。
You can make use of python regular expression.您可以使用 python 正则表达式。
import re
data.jobDescription.apply(lambda x : '.join(re.findall("[a-zA-Z0-9 ]",text)))
The regex pattern will only allow alphabets and numbers, if you want to include symbols, you can add in the pattern to achieve that.正则表达式模式只允许字母和数字,如果你想包含符号,你可以添加模式来实现这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.