4.4 Calculating Statistics on Data

In the next few sections, we perform simple statistics on data sets stored in list structures. For example, let’s assume that we want to analyze statistics on earthquakes worldwide. During one seven-day period, we find that there were 37 earthquakes on Monday, 32 on Tuesday, 46 on Wednesday, 28 on Thursday, 37 on Friday, 41 on Saturday, and 31 on Sunday. This data can be stored in the simple list:

  • [37, 32, 46, 28, 37, 41, 31]

Python’s statistics module can help with our analysis of the data. Table 4.5 highlights some useful functions from this module. To use these functions, we need to import the statistics module. In addition, we can get help from some built-in Python functions, as shown in Table 4.6. All ...

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.