xxxxxxxxxx
# Define the function to remove the punctuation
def remove_punctuations(text):
for punctuation in string.punctuation:
text = text.replace(punctuation, '')
return text
# Apply to the DF series
df['new_column'] = df['column'].apply(remove_punctuations)
xxxxxxxxxx
x = pd.DataFrame(dict(column1=["Lorum. ipsum.?"]))
x["column1"] = x["column1"].str.replace('[^\w\s]','')
xxxxxxxxxx
import pandas as pd
import string
# Sample Pandas Series
data = pd.Series(['Hello, world!', 123, 'Pandas: is great!', None, 'Remove punctuation!'])
# Function to remove punctuation from a string
def remove_punctuation(value):
if isinstance(value, str):
return value.translate(str.maketrans('', '', string.punctuation))
return value
# Apply the function to the series
cleaned_data = data.apply(remove_punctuation)
print(cleaned_data)