Example usage

To use pycounts_s_mck in a project:

Imports

import pycounts_s_mck

from pycounts_s_mck.pycounts_s_mck import count_words
from pycounts_s_mck.plotting import plot_words

Creat a text file

Create a text file to work with for this example.

quote = """“Insanity is doing the same thing over and over and expecting different results.”"""

with open("einstein.txt", "w") as file: 
    file.write(quote)

Count words

We can count the words in our text file using the count_words() function. Note that this function removes punctuation and makes all words lowercase before counting.

counts = count_words("einstein.txt")
print (counts)
Counter({'over': 2, 'and': 2, '“insanity': 1, 'is': 1, 'doing': 1, 'the': 1, 'same': 1, 'thing': 1, 'expecting': 1, 'different': 1, 'results”': 1})

Plot words

We can now plot the result using plot_words() funciton.

fig = plot_words(counts, n= 5)
_images/f8444f5970800806566107c5124e967e52ca5af49a21c5412ab1dcbb56754986.png