AnalystPath

Two Lists, Sorted Apart

PandasMediumMid level~10 min

Problem

An auction tool keeps a DataFrame `auction_book` (loaded from a CSV) with columns `(low_bid, high_bid)`. There is no key and the table may contain duplicate values.

Produce a two-column result that sorts each column independently and lines them up row by row:
1. `low_bid` sorted ascending.
2. `high_bid` sorted descending.
3. The two sorted sequences placed side by side (smallest `low_bid` beside largest `high_bid`, and so on).

The columns are sorted separately, so values that shared a source row are not kept together.

Input data

Example rows — the live problem includes the full dataset.

auction_book
low_bidhigh_bid
4020
2030
3010
1040

Expected output

Your answer should return 4 rows with the columns low_bid, high_bid.

Starter code (Pandas (Python))

import pandas as pd

def two_lists_sorted_apart(auction_book) -> pd.DataFrame:
    # Your code here
    return auction_book

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