Hashtags und Erwähnungen in russischen Tweets
Schauen wir uns noch einmal das DataFrame tweets mit den russischen Tweets an. In dieser Übung zählst du die Anzahl der Hashtags und Erwähnungen in jedem Tweet, indem du zwei Funktionen count_hashtags() und count_mentions() definierst und sie auf das Feature content von tweets anwendest.
Falls du es nicht mehr im Kopf hast: Die Tweets stehen im Feature content von tweets.
Diese Übung ist Teil des Kurses
<Kurs>Feature Engineering für NLP in Python</Kurs>Interaktive praktische Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# 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()