Dataframe BenchMEASURED IN ONE ENVIRONMENT

    ↑↓ to select, Enter to open, Esc to close

    pandas str.rsplit + index is ~15.70× slower than polars str.split + list.get for splitting a string column

    Splits on a hyphen and keeps the first piece.

    Result

    Runpandas str.rsplit + indexpolars str.split + list.getRatio
    Run 1459.8329.2915.70×
    Run 2458.430.2915.14×
    Run 3564.1834.3516.42×

    Spread over 3 runs: pandas str.rsplit + index CV 12.3% / polars str.split + list.get CV 8.6% / ratio CV 4.1%

    The two calls

    df['s'].str.rsplit('-', n=1).str[0]
    df['s'].str.split('-').list.get(0)

    Conditions

    400,000 strings with two hyphens each.

    Where this number does not apply

    Splitting into a list column and exploding it is a different operation.

    Reproduce

    cd bench && python run.py --run 1 --out ../data/run1.json