AnalystPath

Valid Message Routing Keys

PandasEasyJunior level~10 min

Problem

You are given one DataFrame `routing_keys` with columns `record_id` and `handle`, where a handle is shaped like `local@server.net`.

A handle is **valid** only when ALL of these hold: it contains exactly one `@`; the part before the `@` uses only letters, digits, or underscores; the part after the `@` (the server) uses only letters; and it ends in `.net` (lowercase). Missing or empty handles are never valid.

Return columns `record_id` and `handle` for every valid routing key, ordered by `record_id` ascending.

Input data

Example rows — the live problem includes the full dataset.

routing_keys
record_idhandle
1sales_north@hub.net
2finance#hub.net
3support@hub.io
4logistics@depot.net
5intake@local

Expected output

Your answer should return 2 rows with the columns record_id, handle.

Starter code (Pandas (Python))

import pandas as pd

def valid_routing_keys(routing_keys) -> pd.DataFrame:
    # Your code here
    return routing_keys

Solve this Pandas question free

Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related Pandas questions