Operatori su stringhe con i dati di Twitter
Continui a lavorare con i dati tweets in cui la colonna text contiene il contenuto di ogni tweet.
Il tuo compito è trasformare la colonna text in un elenco di token. Poi, usando operatori su stringhe, rimuovi tutti i caratteri non alfabetici dall’elenco di token creato.
Questo esercizio fa parte del corso
Sentiment Analysis con Python
Istruzioni dell'esercizio
- Importa la funzione di tokenizzazione delle parole.
- Crea i token delle parole per ogni tweet.
- Filtra tutti i caratteri non alfabetici dall’elenco creato, cioè mantieni solo le lettere.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Import the word tokenizing package
____
# Tokenize the text column
word_tokens = [____(review) for review in tweets.text]
print('Original tokens: ', word_tokens[0])
# Filter out non-letter characters
cleaned_tokens = [[word for word in item if ____.____] for item in word_tokens]
print('Cleaned tokens: ', cleaned_tokens[0])