-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfiltering.qmd
105 lines (78 loc) · 3.05 KB
/
filtering.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
title: "Filtering"
---
### Filtering
Once you have your data loaded into a plays dataframe, you can perform various filtering operations to focus on specific skills. This section covers techniques for filtering skills such as reception, serve, attack, set, dig, block, and more.
## Python - Filtering for attacks
```{python}
from datavolley import read_dv
import pandas as pd
from IPython.display import Markdown
dv_instance = read_dv.DataVolley(None) # Replace `None` with path of your dvw file
df = dv_instance.get_plays()
atks = df[df['skill'] == 'Attack']
atks = atks.head(5)
Markdown(atks.to_markdown(index = False))
```
------------------------------------------------------------------------
## Python - Filtering for attacks by player
```{python}
atks = df[(df['skill'] == 'Attack') & (df['player_name'] == 'Claire Chaussee')]
atks = atks.head(5)
Markdown(atks.to_markdown(index = False))
```
------------------------------------------------------------------------
## R - Filtering for attacks
```{r}
#| warning: FALSE
library(datavolley)
library(dplyr)
x <- dv_read("datavolley//example_data.dvw") # Example data from python
px <- x$plays
atks <- px %>% filter(skill == 'Attack')
atks <- head(atks, 5)
knitr::kable(atks)
```
------------------------------------------------------------------------
## R - Filtering for attacks by player
```{r}
atks <- px %>% filter(skill == 'Attack' & player_name == 'Claire Chaussee')
atks <- head(atks, 5)
knitr::kable(atks)
```
## Advanced filtering
### Advanced filtering
We can narrow down our analysis to instances where a particular player receives the ball during attacks or when a set code occurs in the preceding skill. This can be achieved using methods that allow us to examine the previous skill or the next skill, enabling targeted filtering for these specific scenarios.
### Python - Filtering for attacks by player reception
```{python}
atks = df[(df['skill'] == 'Attack') &
(df['player_name'] == 'Claire Chaussee') &
(df['player_name'].shift(2) == 'Mel McHenry') &
(df['skill'].shift(2) == 'Reception')]
Markdown(atks.to_markdown(index = False))
```
------------------------------------------------------------------------
### Python - Filtering for attacks by set code
```{python}
atks = df[(df['skill'] == 'Attack') &
(df['player_name'] == 'Claire Chaussee') &
(df['set_code'].shift(1) == 'K1')]
Markdown(atks.to_markdown(index = False))
```
------------------------------------------------------------------------
### R - Filtering for attacks by player reception
```{r}
atks <- px %>% filter(skill == 'Attack' &
player_name == 'Claire Chaussee' &
lag(player_name,2) == 'Mel McHenry' &
lag(skill,2) == 'Reception')
knitr::kable(atks)
```
------------------------------------------------------------------------
### R - Filtering for attacks by set code
```{r}
atks <- px %>% filter(skill == 'Attack' &
player_name == 'Claire Chaussee' &
lag(set_code,1) == 'K1')
knitr::kable(atks)
```