Podcast Search Relevance and Weak-Hit Rate
Problem
You are given a DataFrame `searchhits` loaded from `searchhits.csv` with columns `search_term`, `episode`, `slot`, and `stars`. Each row is one episode that appeared in the results for a search term: `slot` (1 = top) is where it appeared and `stars` (1 to 5) is the score a listener gave it. A search term can have many rows.
For each `search_term`, compute two numbers: `relevance`, the average of `stars / slot` across that term's rows, rounded to 2 decimals; and `weak_hit_pct`, the percentage of that term's rows whose `stars` is below 3, rounded to 2 decimals. Output columns: `search_term`, `relevance`, `weak_hit_pct`.
Input data
Example rows — the live problem includes the full dataset.
| search_term | episode | slot | stars |
|---|---|---|---|
| history | The Roman Road | 1 | 5 |
| history | Lost Empires | 2 | 5 |
| history | Filler Clip | 200 | 1 |
| comedy | Late Set | 5 | 2 |
| comedy | Open Mic | 3 | 3 |
Expected output
Your answer should return 2 rows with the columns search_term, relevance, weak_hit_pct.
Starter code (Pandas (Python))
import pandas as pd
def search_relevance(searchhits) -> pd.DataFrame:
# Your code here
return searchhitsSolve 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