0
つぶやきから👉👌💦✨
などの特殊文字を削除する必要があります。そのために、私はこの戦略(Iは、Python 3を使用)に続く:つぶやきから特殊文字( ``ŒðŸ'`など)を削除する方法
- はそう
Ã
が\xc3\
になり、六角などの特殊文字を取得するために、文字列にバイトからつぶやきを変換します。 - 正規表現を使用して、
b'
とb"
(文字列の先頭)と'
または"
(文字列の最後)を削除します。 - 最後に、正規表現を使用して16進表現を削除します。
import re tweet = 'b"[/Very seldom~ will someone enter your life] to question\xc3\xa2\xe2\x82\xac\xc2\xa6 "' #encoding to 'utf8' tweet_en = tweet.encode('utf8') #converting to string tweet_str = str(tweet_en) #eliminating the b' and b" at the begining of the string: tweet_nob = re.sub(r'^(b\'b\")', '', tweet_str) #deleting the single or double quotation marks at the end of the string: tweet_noendquot = re.sub(r'\'\"$', '', tweet_nob) #deleting hex tweet_regex = re.sub(r'\\x[a-f0-9]{2,}', '', tweet_noendquot) print('this is tweet_regex: ', tweet_regex)
最終的な出力は次のとおりです:
[/Very seldom~ will someone enter your life] to question "
(そこから私はまだ最終"
を削除できませんでした)
は、ここに私のコードです。私は、Twitterデータの特殊文字を整理するためのより良い、より直接的な方法があるのだろうかと思っていました。どんな助けもありがとう。