4.6 Frequency Distribution
As we worked through the steps required to compute the mode of a data set, we actually solved the basic statistics problem of finding the frequency distribution—a representation of the number of times each value occurs in the data.
4.6.1 Using a Dictionary to Compute a Frequency Table
One way to display a frequency distribution is to show a two-column table. The first column gives the data item, and the second gives the associated count. This appears to be similar to our count dictionary. In fact, the only difference is that the table will need to show the items in order. Recall that the dictionary maintains items in the order they were inserted. Our challenge, then, is to sort the data in key order.
To write this ...
Get Python Programming in Context, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.