Malformed Mesh Node Addresses
Problem
You are given a DataFrame `mesh_pings` (loaded from `mesh_pings.csv`) with columns `ping_id`, `node_address`, and `latency_ms`. Every row is a single ping recorded when a node answered, carrying that node's dotted address.
A **well-formed** address is exactly four numbers joined by dots, where each number is between 0 and 255 and carries no leading zero (`7` is fine, `07` is not). An address is **malformed** if any segment exceeds 255, if any segment has a leading zero, or if it does not have exactly four segments.
For every distinct malformed `node_address`, return it together with `invalid_count` -- the number of ping rows that carried it. Order by `invalid_count` descending, then by `node_address` descending.
Input data
Example rows — the live problem includes the full dataset.
| ping_id | node_address | latency_ms |
|---|---|---|
| 1 | 10.20.30.40 | 12 |
| 2 | 260.5.6.7 | 30 |
| 3 | 10.20.030.40 | 12 |
| 4 | 10.20.30.40 | 12 |
| 5 | 10.20.30 | 99 |
Expected output
Your answer should return 3 rows with the columns node_address, invalid_count.
Starter code (Pandas (Python))
import pandas as pd
def find_malformed_nodes(mesh_pings) -> pd.DataFrame:
# Your code here
return mesh_pingsSolve 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