- (Instructor) So now that you've been introduced
to the statistics module and a little bit with lists,
we'd like you to go ahead and create a list
using the values that you see here
and use the statistics module's capabilities
to calculate the mean, the median, and the mode.
So go ahead and pause the video and give that a shot
and then come back to see the results.
Okay, let's go ahead and take a look at the results here.
So, of course in order to use the statistics module,
we need to first import it, which we will do
and we then want you to just to find
a list containing those six values in this case.
So let's go ahead and do that.
Again, comma separated values within square brackets.
And now we have three additional cells here,
each of which uses, from the statistics module,
the mean, the median, or the mode function.
And by the way, notice here in Jupyter Notebooks
that it's color coding the names of the functions
that come from the module to indicate
that they are part of the module's statistics.
So the color coding that you get
may vary from IPython at the command line
to Jupyter Notebooks to the different IDE's
that you might use to implement your Python code.
So we can check the mean of those values by executing this,
notice that we're getting an infinitely repeating sequence.
By default, it shows a maximum of this number of digits
to the right of the decimal point,
rounding to the last position and of course
we could use format strings to get
a nicer looking format of the data.
The median value in this case,
well, they're not sorted up above here
but we could, of course, add another cell
to see what it would look like sorted.
So let me go ahead and do that and let's do sorted
with values as an argument and if I execute that,
you can see these in sorted order
and remember the median is the middle value
but there's not a single middle value here
because we have an even number of items
so what's happening is it's taking the two middle values,
calculating the average of those two values,
and displaying the average so 86
is the average of 84 and 88 of course
and going back up here for a moment,
when we evaluate the mode, whatever appears the most
times 88, in this case, is the mode value so again,
in sorted order, that helps us sees things
like the mode as well because we can see
all of the items of the same value,
side by side with one another.
Now, as long as we are looking at this,
I just want to take a moment and make
one other modification here to show you
what happens, if in fact you don't have a unique mode value.
So we have two 88's, let's go back up here
and add in another 73 and I'll re-execute that cell
so that I now have an updated list in memory
and let's now go re-execute the mode and when we do,
notice we get a statistics error.
The reason is that there was no unique mode value.
There were two values that had
equally common values and if we go back above,
we can see we have two 88's and we have two 73's
so the mode is not always the best type
of central statistic to use because you can't
ever guarantee when you're dealing
with potentially millions of values,
that you have a unique mode value
so you may not see that one used quite as frequently.