Мне нужно декодировать текст в файл
от b'Я знаю, что ты чувствуешь mba mba seperjuangan \ xf0 \ x9f \ x98 \ x90 '
на' b Я знаю, что ты чувствуешьмба мба seperjuangan '
но я получил' б Я знаю, что вы чувствуете мба мба seperjuangan xf xf x x '
я пытался декодировать, но я получил ошибку AttributeError: 'str' object has no attribute 'decode'
tok = WordPunctTokenizer()
pat1 = r'@[A-Za-z0-9]+'
pat2 = r'https?://[A-Za-z0-9./]+'
combined_pat = r'|'.join((pat1, pat2))
def tweet_cleaner(tweet):
soup = BeautifulSoup(tweet)
souped = soup.get_text()
stripped = re.sub(combined_pat, '', souped)
clean = stripped.decode("utf-8","strict").replace(u"\ufffd", "?")
letters_only = re.sub("[^a-zA-Z]", " ", clean)
lower_case = letters_only.lower()
# During the letters_only process two lines above, it has created unnecessay white spaces,
# I will tokenize and join together to remove unneccessary white spaces
words = tok.tokenize(lower_case)
return (" ".join(words)).strip()
testing = df.tweet[:100]
test_result = []
for t in testing:
test_result.append(tweet_cleaner(t))
test_result```