
Lineups above their contest average
mediumLineups above their contest average
FanDuel Pandas Interview Question
A FanDuel score means nothing on its own, because a low scoring slate drags every lineup down. What tells a player whether they drafted well is the distance from the average of the contest they were actually in, and only the lineups that beat it get the badge.
Using the entries DataFrame, keep only the lineups that scored above their own contest average, and return each contest_id, user_id, points, and how far above the average they finished as above_average, rounded to 2 decimal places. Assign the answer to result.
Asked of
- Data Analyst
- Business Analyst
- BI Analyst
- Product Analyst
- Analytics Engineer
- Data Scientist
entriesDataFrame28 rows
| Column Name | Type |
|---|---|
| entry_id | int64 |
| contest_id | str |
| user_id | str |
| joined_at | str |
| points | float64 |
entriesExample Input
| entry_id | contest_id | user_id | joined_at | points |
|---|---|---|---|---|
| 3101 | C1 | U100 | 2024-03-20 18:05:00 | 742.5 |
| 3102 | C1 | U101 | 2024-03-20 18:11:00 | 801 |
| 3103 | C1 | U102 | 2024-03-20 18:14:00 | 801 |
| 3104 | C1 | U103 | 2024-03-20 18:22:00 | 689.5 |
| 3105 | C1 | U104 | 2024-03-20 18:30:00 | 742.5 |
| 3106 | C1 | U105 | 2024-03-20 18:41:00 | 655 |
| 3107 | C1 | U106 | 2024-03-20 18:52:00 | 812.5 |
| 3120 | C4 | U100 | 2024-03-23 17:30:00 | 455.5 |
| 3121 | C4 | U107 | 2024-03-23 17:38:00 | 455.5 |
| 3122 | C4 | U108 | 2024-03-23 17:49:00 | 603 |
| 3123 | C4 | U110 | 2024-03-23 17:55:00 | 588.5 |
| 3124 | C4 | U111 | 2024-03-23 18:04:00 | 721.5 |
Example Output
| contest_id | user_id | points | above_average |
|---|---|---|---|
| C1 | U101 | 801 | 51.86 |
| C1 | U102 | 801 | 51.86 |
| C1 | U106 | 812.5 | 63.36 |
| C4 | U108 | 603 | 38.2 |
| C4 | U110 | 588.5 | 23.7 |
| C4 | U111 | 721.5 | 156.7 |
Explanation
C1 averaged 749.14 points, so the three lineups that beat it are kept and the four below are dropped. U106 finished 63.36 clear of it. C4 is a lower scoring contest, so 603 is above the average there.
The example above is a small slice of the data. Your code runs against the full DataFrames.
Company
FanDuel
Difficulty
medium
Topic
window functions
Language
Pandas
Your code
Loading Python in the background. You can start writing.