Как я могу удалить знаки препинания из определенного столбца в наборе данных python?

#python #machine-learning #nlp

Вопрос:

 def remove_punc(text):  for punctuation in string.punctuation:  text= text.replace(punctuation, "")  return text  def remove_punctuation(text):  return re.sub(r'[^ws]','',text)  

Использование этого возвращает «NaN». PS: столбец уже маркирован и преобразован в нижний регистр.

Ответ №1:

Может быть, попробуйте что-то подобное, так как ваши предложения уже обозначены:

 import string  def remove_punctuation(text):  return text.strip(string.punctuation)  some_sentence = ['whatlt;', 'can!','fishes', 'do?']  new_sentence = [remove_punctuation(token) for token in some_sentence]  print(new_sentence) # ['what', 'can', 'fishes', 'do']