AnalystPath

Popular Exhibit-to-Exhibit Routes

PandasHardSenior level~10 min

Problem

You are given one DataFrame `exhibit_visits` (loaded from `exhibit_visits.csv`), where each row is an exhibit a visitor finished, with columns `visitor_id`, `exhibit_id`, `exhibit_name`, `visited_at` (timestamp), and `enjoyment` (1 to 5). Consider only the enthusiasts: visitors who finished at least 5 exhibits AND whose average enjoyment is at least 4. For those visitors, look at each pair of exhibits visited back-to-back (the exhibit visited immediately after another, in time order), and count how often each ordered pair occurs across all enthusiasts. Return a DataFrame with `from_exhibit`, `to_exhibit`, and the occurrence count as `route_count`. Order by `route_count` descending, then `from_exhibit` ascending, then `to_exhibit` ascending.

Input data

Example rows — the live problem includes the full dataset.

exhibit_visits
visitor_idexhibit_idexhibit_namevisited_atenjoyment
111Gravity Lab2024-01-055
112Tide Pool2024-01-064
113Star Dome2024-01-075
114Robot Arena2024-01-084
115Mirror Maze2024-01-095

Expected output

Your answer should return 5 rows with the columns from_exhibit, to_exhibit, route_count.

Starter code (Pandas (Python))

import pandas as pd

def find_popular_routes(exhibit_visits) -> pd.DataFrame:
    # Your code here
    return exhibit_visits

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