-
Notifications
You must be signed in to change notification settings - Fork 1
/
nfl-injuries.qmd
93 lines (72 loc) · 1.82 KB
/
nfl-injuries.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---
title: "NFL Injuries --- 10 Weeks"
author: "Max Bade"
format:
dashboard:
theme: united
---
```{python}
# prepare data
import pandas as pd
injuries_df = pd.read_csv("nfl-injuries.csv")
group_df = injuries_df.groupby(['data','year'])['row_number'].agg('count').reset_index()
group_df.columns = ['status','year','count_players']
status_avg = group_df.groupby(['status']).mean(1)['count_players'].astype('int')
[out_avg, questionable_avg] = status_avg
injuries_avg = out_avg + questionable_avg
```
# Stats
## Row
```{python}
#| component: valuebox
#| title: Average Injured
dict(
icon = "exclamation-triangle",
color = "primary",
value = injuries_avg
)
```
```{python}
#| component: valuebox
#| title: Average Out
dict(
icon = "x-square",
color = "warning",
value = out_avg
)
```
```{python}
#| component: valuebox
#| title: Average Questionable
dict(
icon = "question-square",
value = questionable_avg
)
```
## Row
```{python}
# injuries by status
import plotly.express as px
px.line(group_df,
x='year', y='count_players',
color='status', text='count_players'
)
```
## Row
```{python}
# total injuries
group_df1 = group_df.groupby('year')['count_players'].agg('sum').reset_index()
group_df1.columns = ['year','count_players']
px.bar(group_df1
,x='year'
,y='count_players'
,text='count_players'
)
```
# Data
This dashboard is based on Max Bade's [NFL Injury Data with BS4 & Plotly in Python](https://maxbade.medium.com/nfl-injury-data-with-bs4-plotly-in-python-f0f89309f5da) article on Medium.
If you want to conduct your own analysis, see the following resources:
| Resource | Link |
|----------------------|--------------------|
| Injuries Dataset | [nfl-injuries.csv](nfl-injuries.csv) |
| Data Scraping Script | [collect.py](collect.py) |