Editor

Build a Data Story with Key Events

Advanced · Write the code · from Data Visualization: Choose the Right Chart and Tell a Story

From the lesson: Data Visualization: Choose the Right Chart and Tell a Story

A chart that looks pretty but tells the wrong story is worse than no chart at all. In 1986, NASA engineers showed managers a chart arguing that cold temperatures could damage the Space Shuttle Challenger's O-ring seals. The chart was so poorly designed that the managers couldn't see the pattern.

Read the lesson

Write a function build_narrative(data, events) where data is a dict of {month: value} and events is a dict of {month: event_description}. The function should return a list of strings, one per event, in the format 'MONTH: VALUE - EVENT'. Only include months that appear in both dicts. Print each narrative line for the test data.

def build_narrative(data, events):
# Build narrative lines for months that have both data and events
pass
data = {
'Jan': 1000, 'Feb': 1100, 'Mar': 900,
'Apr': 950, 'May': 1200, 'Jun': 1400
}
events = {
'Mar': 'Server outage',
'May': 'Marketing campaign launched',
'Jun': 'Product featured on news',
}
narrative = build_narrative(data, events)
for line in narrative:
print(line)

More Data Visualization exercises

All Python exercises · 50 practice problems · Data Science & Machine Learning quiz