top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Count character occurrences in a given word, phrase or sentence.

First we assign a variable to contain the string we want our application to count the number of characters of.

# Contents variable containing the passage we want to count
contents = """Lawrence closed his eyes, listening to the quiet lap lap of water against the old buildings, the drip drip from the gondolier’s oar. Somewhere in the distance a baby was crying, but it was almost silent on the narrowest of narrow canals down which they now proceeded.
There’d been no problem getting a gondola ride. For the second day, a thick white mist hung in the air over the city, and at the gondola station at San Moisè the vessels had loomed out of the fog like Viking ships. A man in a pink T-shirt with horizontal red stripes, and a body-warmer had appeared from nowhere. “You wanna ride, signor e signora? Is foggy. I give you special price of sixty euros!”
Lawrence was surprised when Melissa had showed enthusiasm."""

We import a library called matplotlib.pyplot so that we can visualize the distribution of characters. We will use an empty dictionary so we can properly count each characters.


#import matplotlib.pyplot as plt

inside = dict()
for characters in contents:
        inside[characters]=inside.get(characters,0) + 1

templist = sorted([(key,value) for (value,key) in inside.items()],reverse=True)
print(templist)
templist = dict(templist[:5])

# labels = [x[1] for x in templist]
# values = [x[0] for x in templist]
#prints the result
plt.bar(templist.values(),templist.keys())
plt.show()

The results are astounding. We were able to print out the number of occurrences for each character and we are also able to visualize it.


We can see that spaces are the most frequent with 128 occurrences!


 
 
 

コメント


COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page