0
0
Data Analysis Pythondata~30 mins

Word frequency analysis in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Word frequency analysis
📖 Scenario: Imagine you have a short paragraph of text from a book or an article. You want to find out how many times each word appears in that text. This is useful for understanding which words are used most often.
🎯 Goal: You will create a program that counts how many times each word appears in a given text and then shows the counts.
📋 What You'll Learn
Create a dictionary with words as keys and their counts as values
Use a variable to hold the text to analyze
Use a loop to count the words
Print the final word counts
💡 Why This Matters
🌍 Real World
Word frequency analysis helps in understanding text data, like finding popular topics or keywords in articles, social media, or customer reviews.
💼 Career
Data scientists and analysts use word frequency counts to prepare text data for further analysis or machine learning.
Progress0 / 4 steps
1
Create the text data
Create a variable called text and set it to the exact string: 'Data science is fun and data is powerful'
Data Analysis Python
Hint

Use single or double quotes to create the string exactly as shown.

2
Prepare the word list
Create a variable called words that contains the list of words from text by splitting text on spaces using text.split()
Data Analysis Python
Hint

Use the split() method on the text variable without any arguments.

3
Count the words
Create an empty dictionary called word_counts. Then use a for loop with the variable word to go through each word in words. Inside the loop, add 1 to the count for each word in word_counts. If the word is not in the dictionary, add it with count 1.
Data Analysis Python
Hint

Use dict.get(key, 0) to get the current count or 0 if the word is new.

4
Display the word counts
Write a print statement to display the word_counts dictionary.
Data Analysis Python
Hint

Use print(word_counts) to show the dictionary.