How Often Is Sam Late?

Data with PythonMedium+10 XP+10

How Often Is Sam Late?

A takeaway logs every delivery: which driver took it and how many minutes it took. A delivery is late if it took more than 30 minutes. Exactly 30 is on time.

The manager wants to know what share of one driver's deliveries were late.

Task: write late_share(deliveries, driver).

  • deliveries is a list of dictionaries, each with driver and minutes. Turn it into a DataFrame.
  • Look only at the rows for driver. Names must match exactly, capitals included.
  • Return the percentage of that driver's deliveries that were late, rounded to 1 decimal place.
  • If driver made no deliveries, return 0.0.

Examples

deliveries = [{"driver": "Sam", "minutes": 25}, {"driver": "Jo", "minutes": 41}, {"driver": "Sam", "minutes": 38}, {"driver": "Sam", "minutes": 30}, {"driver": "Jo", "minutes": 22}]
driver = "Sam"
returns 33.3
deliveries = [{"driver": "Sam", "minutes": 25}, {"driver": "Jo", "minutes": 41}, {"driver": "Sam", "minutes": 38}, {"driver": "Sam", "minutes": 30}, {"driver": "Jo", "minutes": 22}]
driver = "Jo"
returns 50.0

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run