AnalystPath

Triple Consecutive Sensor Codes

PandasMediumMid level~10 min

Problem

A machine records a status `code` on every tick. Ticks are numbered sequentially with no gaps.

**DataFrame: `tick_log`**

| Column | Type |
|---------|------|
| tick_no | int |
| code | int |

`tick_no` is unique and increases by 1 with no gaps.

Return a DataFrame with one column `repeated_code` listing every status `code` that appears in **at least three consecutive ticks**. Report each qualifying code once, in any order.

Input data

Example rows — the live problem includes the full dataset.

tick_log
tick_nocode
17
27
37
49
57

Expected output

Your answer should return 1 row with the columns repeated_code.

Starter code (Pandas (Python))

import pandas as pd

def triple_run_codes(tick_log) -> pd.DataFrame:
    # Your code here
    return tick_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