TED talks का word count
ted एक dataframe है जिसमें 500 TED talks के transcripts हैं. आपका कार्य एक नया फीचर word_count निकालना है, जो हर talk के लगभग शब्दों की संख्या रखे. इसके साथ, आपको talks के औसत word count की भी गणना करनी है. Transcripts, ted में transcript फीचर के रूप में उपलब्ध हैं.
यह कार्य पूरा करने के लिए, आपको एक फंक्शन count_words परिभाषित करना होगा जो एक string арг्युमेंट ले और उस string में शब्दों की संख्या लौटाए. इसके बाद, आपको इस फंक्शन को ted के transcript फीचर पर apply करके नया फीचर word_count बनाना है और उसका mean निकालना है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में NLP के लिए Feature Engineering
अभ्यास निर्देश
split()मेथड का उपयोग करकेstringको शब्दों की list में बाँटें.len()का उपयोग करकेwordsमें मौज़ूद elements की संख्या लौटाएँ.- अपने फंक्शन को
tedकीtranscriptकॉलम पर apply करके नया फीचरword_countबनाएँ. mean()का उपयोग करके talks के औसत word count की गणना करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Function that returns number of words in a string
def count_words(string):
# Split the string into words
words = ____.____
# Return the number of words
return ____(____)
# Create a new feature word_count
ted['word_count'] = ted[____].apply(____)
# Print the average word count of the talks
print(ted[____].____)