Remove punctuations in pandas [duplicate] Remove punctuations in pandas [duplicate] pandas pandas

Remove punctuations in pandas [duplicate]


Using Pandas str.replace and regex:

df["new_column"] = df['review'].str.replace('[^\w\s]','')


You can build a regex using the string module's punctuation list:

df['review'].str.replace('[{}]'.format(string.punctuation), '')


I solved the problem by looping through the string.punctuation

def remove_punctuations(text):    for punctuation in string.punctuation:        text = text.replace(punctuation, '')    return text

You can call the function the same way you did and It should work.

df["new_column"] = df['review'].apply(remove_punctuations)