Summarizing Data Practice
Introduction
Welcome back to Summarizing Data. We’re at lesson five, the final lesson in this course. There’s no new NumPy tool to learn today. Instead, we’ll practice choosing which familiar tool comes next: creating arrays, cleaning values, calculating, selecting, and summarizing. By the end, we’ll turn a week of coffee-cup sales into a short set of useful answers with one clear script.
Meet the Dataset and Its Structure
Imagine that a café has recorded how many cups it sold each day. One entry is -1, a marker indicating that the till failed and the real count is unknown. We’ll first turn the list into an array, then create matching day numbers with np.arange, a factory function from an earlier course. Days are numbered starting at 1, so the labels are 1 through 7. Each position in the two arrays describes the same day, so we can use a cup count or its revenue to look up the corresponding day. As always, we import NumPy as np first; the later snippets in this lesson use the same import.
cups holds the recorded counts, while days holds the labels 1 through 7. The printed arrays show the failed-till marker in the third position, next to the label for day 3:
Keeping the arrays aligned will let us connect selected sales values to their day numbers later.
Handle the Unknown Day with Mask Assignment
Before calculating revenue, we must decide what to do with the failed-till marker, because -1 cups would produce negative revenue. As you may recall from an earlier course, a comparison creates a Boolean mask, and assigning through that mask updates matching values in place. For this exercise we make a simplifying assumption: we treat the unknown day as 0 cups.
The comparison cups < 0 marks the -1 entry, and the assignment changes it to 0 while leaving the other counts alone, as the printed array shows:
Keep in mind what this means: the café almost certainly sold some cups that day, we just don’t know how many. Every total and average below is therefore “under the zero assumption,” and the true weekly figures are probably a little higher.
