AnalystPath

Malformed Mesh Node Addresses

PandasHardSenior level~10 min

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.

mesh_pings
ping_idnode_addresslatency_ms
110.20.30.4012
2260.5.6.730
310.20.030.4012
410.20.30.4012
510.20.3099

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_pings

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