example_package¶
Submodules¶
Attributes¶
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. |
|
Plot the top N words from the word counts. |
Package Contents¶
- example_package.__version__¶
- 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)]