Working with 2017 NFL Quarterback Data, looking to put the top 10 qbs each week in a dataframe (along with the rest of the data).
qb = {'week': [1, 1, 1, 2, 2, 2], 'qb': ['Rodgers', 'Brady', 'Wilson', 'Rodgers', 'Brady', 'Wilson'], 'pts': [30, 24, 20, 31, 20, 26]}
qb_df = pd.DataFrame(data=qb)
week qb pts
1 Rodgers 30
1 Brady 24
1 Wilson 20
2 Rodgers 31
2 Brady 20
3 Wilson 26
For this sake looking to return the top 2 from each week into a new dataframe.
week qb pts
1 Rodgers 30
1 Brady 24
2 Rodgers 31
2 Wilson 26
I tried a for loop that works as far as getting the data, but can't figure out to put it in a dataframe
top10_17 = pd.DataFrame()
for i in range(1, 18):
i_17 = qb_2017.loc[qb_2017['Week'] == i].sort_values('FantasyPoints', ascending=False)[:10]
top10_17 = pd.concat(i_17)
Used range(1,18) for the 17 weeks in an NFL season