Selecting Columns and Filtering Rows

~10 mincode completion

Write high_scorers(df, threshold) that returns the rows where score is strictly greater than threshold.

Examples

Only rows above the threshold survive

Input
high_scorers({"name": ["a", "b", "c"], "score": [90, 70, 85]}, 80)
shape of result
[2, 2]

A row exactly at the threshold is excluded, since the test is strict

Input
high_scorers({"name": ["a", "b"], "score": [80, 81]}, 80)
shape of result
[1, 2]

Nothing above the threshold gives an empty frame, not an error

Input
high_scorers({"name": ["a"], "score": [10]}, 50)
shape of result
[0, 2]

Hints

Hint 1

Index the array with a boolean mask to keep only the elements that match.

Hint 2

Reach for ampersand rather than and.

Requirements

  • : a DataFrame with a "score" column

  • threshold: a number

  • Return the subset of rows where score > threshold.

Constraints

  • Standard library only, no imports required

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~10 min

8 employers weight this skill

2 big tech firms, 2 frontier labs, 1 AI product company, 1 defense company, 1 enterprise vendor, 1 quant fund. Top match scores 63.

Python
import pandas as pd

def high_scorers(df, threshold):
    """
    Keep only the rows above a score threshold.

    Args:
        df: a DataFrame with a "score" column
        threshold: a number

    Returns:
        The subset of rows where score > threshold.
    """
    # YOUR CODE HERE
    pass

def _run(df, threshold):
    """Builds a DataFrame from plain data, then calls high_scorers."""
    import pandas as pd
    return high_scorers(pd.DataFrame(df), threshold)


def _score_total(df, threshold):
    """Total of the surviving score column."""
    import pandas as pd
    return float(high_scorers(pd.DataFrame(df), threshold)["score"].sum())

Run your code to see results

⌘↵ runs against the visible tests

Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.