pycounts_tt25

Submodules

Attributes

Functions

count_words(input_file)

Count words in a text file.

plot_words(word_counts[, n])

Plot a bar chart of word counts.

Package Contents

pycounts_tt25.__version__
pycounts_tt25.count_words(input_file)[source]

Count words in a text file.

Words are made lowercase and punctuation is removed before counting.

Parameters:

input_file (str) – Path to text file.

Returns:

dict-like object where keys are words and values are counts.

Return type:

collections.Counter

Examples

>>> count_words("text.txt")
pycounts_tt25.plot_words(word_counts, n=10)[source]

Plot a bar chart of word counts.

Parameters:
  • word_counts (collections.Counter) – Counter object of word counts.

  • n (int, optional) – Plot the top n words. By default, 10.

Returns:

Bar chart of word counts.

Return type:

matplotlib.container.BarContainer

Examples

>>> from pycounts.pycounts import count_words
>>> from pycounts.plotting import plot_words
>>> counts = count_words("text.txt")
>>> plot_words(counts)