Exercise · beginner · 10 min
Label unknown categories, keep missing numbers missing
A report needs every visit in a region bucket, so a missing region becomes "unknown". A missing duration is different: filling it with 0 would drag the average down.
The rules
These rules decide what a correct result is. Your answer is checked on this dataset and on hidden datasets that follow the same rules.
Input visits(id, region, duration_min) — text. id is unique. Rules region: remove ASCII whitespace at both ends; an empty result is missing; then a missing region becomes the label "unknown" (the report groups by region and needs a bucket for it). duration_min: remove ASCII whitespace at both ends; an empty result is missing; convert to a whole number. A missing duration stays missing. Never fill it with 0 or any other number. Every duration that is present is a valid whole number. Output (row order does not matter) clean(id text, region text, duration_min int64)
The data
visits · 15 rows, first 12 shown
| id | region | duration_min |
|---|---|---|
| vplbs | East | ·80· |
| vivo8 | ·East | 108 |
| v08ub | empty | missing |
| vtj0d | South | 0 |
| v59m5 | ·North | ·66· |
| vo7m1 | missing | empty |
| v67u0 | empty | 0 |
| vpbs2 | West | ·28· |
| vep98 | West | 0 |
| vfx87 | ·North | ·66· |
| vgnmc | ·North | missing |
| vmoeo | empty | 83 |
What you practise
- missing values
- filling
- blank text
- type conversion
Your answer is also checked on hidden datasets generated from the same rules.
Sign in to bookmark this and keep private notes.