DEV Community

Durga Pokharel
Durga Pokharel

Posted on

Day 92 Of 100DaysOfCode: Charting Practice

Today is my 92th day of #100daysofcode and #python learning journey. Today also keep learning from DataCamp completed some assignments here. Studied some articles from dev. Following code for charting using matplotlib and tokenization.

Code

# Split the script into lines: lines
lines = holy_grail.split('\n')

# Replace all script lines for speaker
pattern = "[A-Z]{2,}(\s)?(#\d)?([A-Z]{2,})?:"
lines = [re.sub(pattern, '', l) for l in lines]

# Tokenize each line: tokenized_lines
tokenized_lines = [regexp_tokenize(s, "\w+") for s in lines]

# Make a frequency list of lengths: line_num_words
line_num_words = [len(t_line) for t_line in tokenized_lines]

# Plot a histogram of the line lengths
plt.hist(line_num_words)

# Show the plot
plt.show()
Enter fullscreen mode Exit fullscreen mode

Day 92 Of #100DaysOfCode and #Python
Natural Language Processing(Charting practice) From DataCamp.#WomenWhoCode #womenintech #CodeNewbie #DEVCommunity pic.twitter.com/IuPJ5SzGhp

— Durga Pokharel (@durgacodes) March 31, 2021

Top comments (1)

Collapse
 
otumianempire profile image
Michael Otu

Well done. Just 8 days more. I hope you'd share your experience and tips, do's and dont's.