Popular Exhibit-to-Exhibit Routes
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.
| visitor_id | exhibit_id | exhibit_name | visited_at | enjoyment |
|---|---|---|---|---|
| 1 | 11 | Gravity Lab | 2024-01-05 | 5 |
| 1 | 12 | Tide Pool | 2024-01-06 | 4 |
| 1 | 13 | Star Dome | 2024-01-07 | 5 |
| 1 | 14 | Robot Arena | 2024-01-08 | 4 |
| 1 | 15 | Mirror Maze | 2024-01-09 | 5 |
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_visitsSolve 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