Я пытаюсь предварительно обработать текст как часть НЛП. Я новичок в этом. Я не понимаю, почему я не могу заменить цифры
para = "support leaders around the world who do not speak for the big
polluters, but who speak for all of humanity, for the indigenous people of
the world, for the first 100 people.In 90's it seems true."
import re
import nltk
sentences = nltk.sent_tokenize(para)
for i in range(len(sentences)):
words = nltk.word_tokenize(sentences[i])
words = [re.sub(r'\d','',words)]
sentences[i] = ' '.join(words)
, делая это, я получаю следующееошибка:
TypeError Traceback (most recent call last)
<ipython-input-28-000671b45ee1> in <module>()
2 for i in range(len(sentences)):
3 words = nltk.word_tokenize(sentences[i])
----> 4 words = [re.sub(r'\d','',words)].encode('utf8')
5 sentences[i] = ' '.join(words)
~\Anaconda3\lib\re.py in sub(pattern, repl, string, count, flags)
189 a callable, it's passed the match object and must return
190 a replacement string to be used."""
--> 191 return _compile(pattern, flags).sub(repl, string, count)
192
193 def subn(pattern, repl, string, count=0, flags=0):
TypeError: expected string or bytes-like object
Как я могу преобразовать в байтовый объект.Я смущен, поскольку я новичок в этом.