import pandas as pd
pd.set_option('max_colwidth', 400)
df = pd.DataFrame({'Reviews':['dealer said it does not reimburse dealers for loaners or rentals... so why even be a dealership if they make faulty cars and you re on the line to help customers']})
df['Reviews'] = df['Reviews'].replace('\.+','.',regex=True)
print(df)
import re
regex = r"(\W)\1+"
test_str = "dealer said it does not reimburse dealers for loaners or rentals... so why even be a dealership if they make faulty cars and you re on the line to help customers"
subst = "\\1"
result = re.sub(regex, subst, test_str, 0, re.MULTILINE)
if result:
print (result)
你可以尝试以下任何一种方法-
带REGEX
带REGEX
^{pr2}$带REGEX
如果您想从每一行中删除这个特定的单词,那么就不需要使用RegEx。您可以使用
str.replace
,如下所示:How to strip a specific word from a string?在系列结构更换适用于简单表达式:
相关问题 更多 >
编程相关推荐