Lineups above their contest average

window functions

Lineups 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 NameType
entry_idint64
contest_idstr
user_idstr
joined_atstr
pointsfloat64

entriesExample Input

entry_idcontest_iduser_idjoined_atpoints
3101C1U1002024-03-20 18:05:00742.5
3102C1U1012024-03-20 18:11:00801
3103C1U1022024-03-20 18:14:00801
3104C1U1032024-03-20 18:22:00689.5
3105C1U1042024-03-20 18:30:00742.5
3106C1U1052024-03-20 18:41:00655
3107C1U1062024-03-20 18:52:00812.5
3120C4U1002024-03-23 17:30:00455.5
3121C4U1072024-03-23 17:38:00455.5
3122C4U1082024-03-23 17:49:00603
3123C4U1102024-03-23 17:55:00588.5
3124C4U1112024-03-23 18:04:00721.5

Example Output

contest_iduser_idpointsabove_average
C1U10180151.86
C1U10280151.86
C1U106812.563.36
C4U10860338.2
C4U110588.523.7
C4U111721.5156.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.