Building Your First Word Frequency Table
Tally how often each word appears.
Building Your First Word Frequency Table is a free NLP Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the NLP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is a Frequency Table?
A frequency table maps each word to how many times it appears. It is the foundation of nearly every text analysis. 📊
Start With Tokens
First turn text into a list of words, then lowercase them so The and the count as the same token.
words = text.lower().split()Count With a Dictionary
A Python dictionary stores word to count pairs. You loop through words and add one each time a word appears.
freq = {}
for w in words:
freq[w] = freq.get(w, 0) + 1The get Trick
Using get with a default of zero avoids errors when a word is seen for the first time. It keeps the loop clean.
freq[w] = freq.get(w, 0) + 1Counter Does It for You
The Counter class from collections builds the whole table in one line, no manual loop needed.
from collections import Counter
freq = Counter(words)Look Up a Word
With the table built, reading a count is instant. Just index the word and you get its frequency.
print(freq["the"]) # how many times the appearsFind the Most Common
Counter's most_common method returns the top words and their counts, already sorted from highest to lowest.
print(freq.most_common(3))Stopwords Dominate
The top of almost every table is stopwords like the, of, and a. They are frequent but carry little meaning.
Sort Your Own Dictionary
To rank a plain dict, sort its items by value. The sorted function with a key gives you the order you want.
ranked = sorted(freq.items(), key=lambda x: x[1], reverse=True)Frequencies Power Features
This table is the seed of bag-of-words, where word counts become the numbers that machine learning models read.
Loop to Print the Table
Iterate over the items to display each word beside its count, giving you a readable summary of the document.
for word, n in freq.items():
print(word, n)Quick Check
Pick the fastest way to build a word count table.
Recap: Your Frequency Table
You built a frequency table with a dict or Counter, ranked the top words, and saw how counts feed bag-of-words features. 🎉
Frequently asked questions
Is the “Building Your First Word Frequency Table” lesson free?
Yes — the full text of “Building Your First Word Frequency Table” is free to read here on the web, and the NLP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the NLP Academy course, upgrade to CoddyKit PRO.
What will I learn in “Building Your First Word Frequency Table”?
Tally how often each word appears. You practise NLP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start NLP Academy?
No prior experience is required. NLP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Building Your First Word Frequency Table” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this NLP Academy lesson?
Yes. Every NLP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Strings, Characters, and Encodings
- Reading Text Files Into Python
- Counting Words and Characters
- Building Your First Word Frequency Table