【发布时间】:2021-10-05 23:14:02
【问题描述】:
我有这样的文字Cat In A Tea Cup by New Yorker cover artist Gurbuz Dogan Eksioglu,Handsome cello wrapped hard magnet, Ideal for home or office.
我通过以下代码从该文本中删除了标点符号。
import string
string.punctuation
def remove_punctuation(text):
punctuationfree="".join([i for i in text if i not in string.punctuation])
return punctuationfree
#storing the puntuation free text
df_Train['BULLET_POINTS']= df_Train['BULLET_POINTS'].apply(lambda x:remove_punctuation(x))
df_Train.head()
在上面的代码中df_Train 是一个熊猫数据框,其中“BULLET_POINTS”列包含上述类型的文本数据。
我得到的结果是Cat In A Tea Cup by New Yorker cover artist Gurbuz Dogan EksiogluHandsome cello wrapped hard magnet Ideal for home or office
请注意 Eksioglu 和 Handsome 两个词是如何组合在一起的,因为 , 之后没有空格。我需要一种方法来解决这个问题。
【问题讨论】:
-
不要删除,用空格代替。
标签: python regex pandas dataframe