Classify the Days
Beginner · Write the code · from Extracting Information from Data: Cleaning, Filtering and Metadata
From the lesson: How do patterns emerge from data?
Sorted by date, the sales numbers jump up and down. Transform the same data by sorting it by temperature, and a pattern appears that was there all along. The program below also classifies each day: it puts every day into one of three categories chosen in advance (cool, warm, hot).
Read this part of the lessonWrite count_by_label(temps). It takes a list of daily high temperatures in °F and returns a dictionary counting how many days fall in each category: 'cool' (below 70), 'warm' (70 to 79) and 'hot' (80 or above). Always include all three keys, in the order cool, warm, hot, even when a count is 0.
count_by_label([74, 85, 63]) -> {'cool': 1, 'warm': 1, 'hot': 1}What Check runs
Your code runs first, then each of these lines, and 1 more that stay hidden. The output must match exactly.
| Runs | Expected output |
|---|---|
| print(count_by_label([74, 85, 63])) | {'cool': 1, 'warm': 1, 'hot': 1} |
| print(count_by_label([74, 85, 63, 91, 68, 88, 72])) | {'cool': 2, 'warm': 2, 'hot': 3} |
| print(count_by_label([])) | {'cool': 0, 'warm': 0, 'hot': 0} |
More Data Filtering exercises
- Clean a City NameBeginner
- Combine Two SourcesIntermediate
- Average on Hot DaysIntermediate