0Pricing
NLP Academy · Aula

Criando sua primeira tabela de frequência de palavras

Conte quantas vezes cada palavra aparece.

Criando sua primeira tabela de frequência de palavras é uma aula grátis de NLP Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de NLP Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de NLP Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

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) + 1

The 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) + 1

Counter 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 appears

Find 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. 🎉

Perguntas Frequentes

A aula “Criando sua primeira tabela de frequência de palavras” é grátis?

Sim — o texto completo de “Criando sua primeira tabela de frequência de palavras” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de NLP Academy, atualize para CoddyKit PRO. O curso de NLP Academy inclui 4 aulas no total.

O que vou aprender em “Criando sua primeira tabela de frequência de palavras”?

Conte quantas vezes cada palavra aparece. Você pratica NLP Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar NLP Academy?

Nenhuma experiência prévia é necessária. NLP Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Criando sua primeira tabela de frequência de palavras”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de NLP Academy?

Sim. Cada aula de NLP Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Cadeias de caracteres, caracteres e codificações
  2. Lendo arquivos de texto no Python
  3. Contando palavras e caracteres
  4. Criando sua primeira tabela de frequência de palavras
← Voltar para NLP Academy