example_package

Submodules

Attributes

__version__

Functions

load_text(file_path)

Load text from a file.

clean_text(text)

Clean the text by removing punctuation and converting to lowercase.

count_words(input_file)

Count the frequency of each word in the input file.

plot_words(word_counts[, top_n])

Plot the top N words from the word counts.

Package Contents

example_package.__version__
example_package.load_text(file_path)[source]

Load text from a file.

example_package.clean_text(text)[source]

Clean the text by removing punctuation and converting to lowercase.

example_package.count_words(input_file)[source]

Count the frequency of each word in the input file.

Parameters:

input_file (str) – Path to the text file to analyze.

Returns:

A Counter object containing word frequencies where:
  • keys are the unique words found in the text

  • values are the number of occurrences of each word

Return type:

Counter

Example

>>> word_counts = count_words("sample.txt")
>>> word_counts["hello"]
3
>>> word_counts.most_common(1)
[('hello', 3)]
example_package.plot_words(word_counts: collections.Counter, top_n=10)[source]

Plot the top N words from the word counts.