AnalystPath

Flagging Patterns in Request Lines

PandasMediumMid level~10 min

Problem

You are given a DataFrame `request_log` (loaded from `request_log.csv`) with columns `line_id`, `path_text`, and `service`. Each row holds one captured request path and the service that emitted it.

Compute four diagnostic flags for every row, based on its `path_text`:

- `is_api`: 1 if the path begins with `/api`.
- `is_versioned`: 1 if the path ends with `v1`, `v2`, or `v3`.
- `has_admin`: 1 if the path contains the substring `admin`.
- `has_double_slash`: 1 if the path contains three or more consecutive slashes (`///`).

Return every row together with the four flag columns (`line_id`, `path_text`, `service`, `is_api`, `is_versioned`, `has_admin`, `has_double_slash`), ordered by `line_id`.

Input data

Example rows — the live problem includes the full dataset.

request_log
line_idpath_textservice
1/api/users/list/v2gateway
2////healthgateway
3/admin/panel/homeconsole
4/api/admin/v3console
5/static/logo.pngcdn

Expected output

Your answer should return 7 rows with the columns line_id, path_text, service, is_api, is_versioned, has_admin, has_double_slash.

Starter code (Pandas (Python))

import pandas as pd

def flag_request_lines(request_log) -> pd.DataFrame:
    # Your code here
    return request_log

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