example_package.counts¶
Functions¶
|
Load text from a file. |
|
Clean the text by removing punctuation and converting to lowercase. |
|
Count the frequency of each word in the input file. |
Module Contents¶
- example_package.counts.clean_text(text)[source]¶
Clean the text by removing punctuation and converting to lowercase.
- example_package.counts.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)]