我想清理我的评论数据。我的代码是:def processData(data):
data = data.lower() #casefold
data = re.sub(']*>',' ',data) #remove any html
data = re.sub(r'#([^\s]+)', r'\1', data) #Replace #word with word
remove = string.punctuation
remove = remove.replace("'", "") # don't remove '
p = r"[{}]".format(remove) #create the pattern
data = re.sub(p, "", data)
data = re.sub('[\s]+', ' ', data) #remove additional whitespaces
pp = pile(r"(.)\1{1,}", re.DOTALL) #pattern for remove repetitions
data = pp.sub(r"\1\1", data)
return data
这段代码几乎可以正常工作,但是仍然有一个问题。
因为这句话“她在公共服务部门工作”
我知道“她在公共服务部门工作”。在
问题是字符串标点后没有空格。在
我希望我的句子是这样的“她在公共服务部门工作”。在
你能帮我写代码吗?在