Hashtag e menzioni nei tweet in russo
Riprendiamo il dataframe tweets con i tweet in russo. In questo esercizio calcolerai il numero di hashtag e di menzioni in ogni tweet definendo due funzioni, count_hashtags() e count_mentions(), e applicandole alla caratteristica content di tweets.
Se non lo ricordassi, i tweet sono contenuti nella caratteristica content di tweets.
Questo esercizio fa parte del corso
Feature Engineering per NLP in Python
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Function that returns numner of hashtags in a string
def count_hashtags(string):
# Split the string into words
words = string.split()
# Create a list of words that are hashtags
hashtags = [word for word in words if ____.____(____)]
# Return number of hashtags
return(len(hashtags))
# Create a feature hashtag_count and display distribution
tweets['hashtag_count'] = tweets['content'].apply(count_hashtags)
tweets['hashtag_count'].hist()
plt.title('Hashtag count distribution')
plt.show()