Hashtagi i wzmianki w rosyjskich tweetach
Wróćmy do ramki danych tweets zawierającej rosyjskie tweety. W tym ćwiczeniu obliczysz liczbę hashtagów i wzmianek w każdym tweecie – zdefiniujesz w tym celu dwie funkcje: count_hashtags() oraz count_mentions(), a następnie zastosujesz je do cechy content ramki tweets.
Przypominamy, że treść tweetów znajduje się w cesze content ramki tweets.
To ćwiczenie jest częścią kursu
Inżynieria cech dla NLP w Pythonie
Interaktywne ćwiczenie praktyczne
Spróbuj tego ćwiczenia, uzupełniając ten przykładowy kod.
# 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()