शुरू करेंमुफ़्त में शुरू करें

रूसी ट्वीट्स में हैशटैग और मेंशन्स

आइए tweets डेटाफ़्रेम जिसमें रूसी ट्वीट्स हैं, उसे फिर से देखें। इस अभ्यास में, आप प्रत्येक ट्वीट में हैशटैग और मेंशन्स की संख्या निकालेंगे। इसके लिए दो फंक्शन count_hashtags() और count_mentions() परिभाषित कीजिए और उन्हें tweets के content फीचर पर अप्लाई कीजिए.

यदि आपको याद न हो, तो ट्वीट्स tweets के content फीचर में ही मौजूद हैं.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Python में NLP के लिए Feature Engineering

पाठ्यक्रम देखें

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# 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()
कोड संपादित करें और चलाएँ