nflverse / nfl_data_py

Python code for working with NFL play by play data.
MIT License
287 stars 54 forks source link

[FEATURE REQ] import_weekly_data() to pull weekly defensive performances #119

Open sedric11 opened 1 month ago

sedric11 commented 1 month ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe.

Currently the offensive stats are pulled into the weekly data. However in daily fantasy sports, a DST position exists where each team's sacks, turnovers recovered, and return touchdowns are also calculated. It would be helpful if that position was returned in the weekly function.

# Function to get weekly data
def get_weekly_data(year):
    year_list = [int(year)]
    df = nfl.import_weekly_data(year_list)
    print(df['position'].value_counts())
    return df

position WR 614 RB 385 TE 296 QB 195 FB 19 P 3 T 3 SS 1 CB 1

Describe the solution you'd like

Return an aggregate of the team's sacks, fumble recoveries, interceptions, blocked kicks, safeties, kick returns/interception/fumble recoveries when they result in a defensive touchdown, and points allowed to reflect the team's defensive performance for the given week.

Describe alternatives you've considered

No alternative exists in this program that I'm aware of

Additional context

Here is a list of all the relevant defensive stats that are used by draftkings and fanduel for daily fantasy scoring:

Defense -- Sack | +1 Pt Interception | +2 Pts Fumble Recovery | +2 Pts Punt/Kickoff/FG Return for TD | +6 Pts Interception Return TD | +6 Pts Fumble Recovery TD | +6 Pts Blocked Punt or FG Return TD | +6 Pts Safety | +2 Pts Blocked Kick | +2 Pts 2 Pt Conversion/Extra Point Return | +2 Pts 0 Points Allowed | +10 Pts 1 – 6 Points Allowed | +7 Pts 7 – 13 Points Allowed | +4 Pts 14 – 20 Points Allowed | +1 Pt 21 – 27 Points Allowed | +0 Pts 28 – 34 Points Allowed | -1 Pt 35+ Points Allowed | -4 Pts
alecglen commented 1 week ago

import_weekly_data() and import_seasonal_data() provide player-level data, so I'll make the update to include data for defensive players. From there, you can aggregate them by position to generate DST numbers.