Reader small image

You're reading from  Jupyter for Data Science

Product typeBook
Published inOct 2017
Reading LevelBeginner
PublisherPackt
ISBN-139781785880070
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Dan Toomey
Dan Toomey
author image
Dan Toomey

Dan Toomey has been developing application software for over 20 years. He has worked in a variety of industries and companies, in roles from sole contributor to VP/CTO-level. For the last few years, he has been contracting for companies in the eastern Massachusetts area. Dan has been contracting under Dan Toomey Software Corp. Dan has also written R for Data Science, Jupyter for Data Sciences, and the Jupyter Cookbook, all with Packt.
Read more about Dan Toomey

Right arrow

Visualizing average ratings by cuisine


Now that we have the cuisine averages computed, we can display them in a histogram to get an idea of their spread. We first convert the dictionary to a data frame. Then plot the Rating column of the data frame into a histogram:

Note

We are using five bins to correspond to the five possible ratings.

import pandas as pdimport numpy as npdf = pd.DataFrame(columns=['Cuisine', 'Rating'])for cuisine in cuisines:    df.loc[len(df)]=[cuisine, cuisines[cuisine]]hist, bin_edges = np.histogram(df['Rating'], bins=range(5))import matplotlib.pyplot as pltplt.bar(bin_edges[:-1], hist, width = 1)plt.xlim(min(bin_edges), max(bin_edges))plt.show()   

Again, we see a clear mark towards high average values. I had tried to get a better gradient on the data display to no avail.

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Jupyter for Data Science
Published in: Oct 2017Publisher: PacktISBN-13: 9781785880070

Author (1)

author image
Dan Toomey

Dan Toomey has been developing application software for over 20 years. He has worked in a variety of industries and companies, in roles from sole contributor to VP/CTO-level. For the last few years, he has been contracting for companies in the eastern Massachusetts area. Dan has been contracting under Dan Toomey Software Corp. Dan has also written R for Data Science, Jupyter for Data Sciences, and the Jupyter Cookbook, all with Packt.
Read more about Dan Toomey