Professional Documents
Culture Documents
Data Analyst Exam 2
Data Analyst Exam 2
(Dataset taken from Kaggle - Thanks for that. Click the link to visit!)
the Nigeria-Iceland match during World Cup 2018 (Which ended 2-0 to Nigeria!)
e as substitutes.
than one position during the game
re game (From start to the final whistle, without being substituted)
positions
[]
[{'position_id': 13, 'position': 'Right Center Midfield', 'from': '00:00', 'to': '89:47',
'from_period': 1, 'to_period': 2, 'start_reason': 'Starting XI', 'end_reason': 'Tactical
Shift'}, {'position_id': 14, 'position': 'Center Midfield', 'from': '89:47', 'to': None,
'from_period': 2, 'to_period': None, 'start_reason': 'Tactical Shift', 'end_reason':
'Final Whistle'}]
[{'position_id': 15, 'position': 'Left Center Midfield', 'from': '89:40', 'to': '89:47',
'from_period': 2, 'to_period': 2, 'start_reason': 'Substitution - On (Tactical)',
'end_reason': 'Tactical Shift'}, {'position_id': 19, 'position': 'Center Attacking
Midfield', 'from': '89:47', 'to': None, 'from_period': 2, 'to_period': None,
'start_reason': 'Tactical Shift', 'end_reason': 'Final Whistle'}]
[{'position_id': 24, 'position': 'Left Center Forward', 'from': '00:00', 'to': '84:03',
'from_period': 1, 'to_period': 2, 'start_reason': 'Starting XI', 'end_reason':
'Substitution - Off (Tactical)'}]
[{'position_id': 24, 'position': 'Left Center Forward', 'from': '84:03', 'to': '89:47',
'from_period': 2, 'to_period': 2, 'start_reason': 'Substitution - On (Tactical)',
'end_reason': 'Tactical Shift'}, {'position_id': 22, 'position': 'Right Center Forward',
'from': '89:47', 'to': None, 'from_period': 2, 'to_period': None, 'start_reason':
'Tactical Shift', 'end_reason': 'Final Whistle'}]
[{'position_id': 22, 'position': 'Right Center Forward', 'from': '00:00', 'to': '89:47',
'from_period': 1, 'to_period': 2, 'start_reason': 'Starting XI', 'end_reason': 'Tactical
Shift'}, {'position_id': 24, 'position': 'Left Center Forward', 'from': '89:47', 'to':
None, 'from_period': 2, 'to_period': None, 'start_reason': 'Tactical Shift',
'end_reason': 'Final Whistle'}]
e link to visit!)
Please scroll down to see answers!
Answer 1 =COUNTIF(G4:G23,"<>[]")
To count the number of players that received a card (yellow or red), we need to count the entries that are not empty (emp
To do that, we use the COUNTIF function, combined with the <> operator (not equal). We are basically looking for anythin
2 Return the names of the players that joined the game as substitutes.
Players that joined as substitutes, have the following text in their "positions" column:
start_reason': 'Substitution - On (Tactical)'
We can basically ask Excel to keep only rows where "Substitution - On" appears as this is a good indicator for that.
First, we will use the SEARCH function to look for the string "substitution - on" in the "positions" column.
We can see that only three cells contain a number - that number represents the character position in which "substitution -
Where we see a #VALUE! error we know that we didn't find a match.
Note we used SEARCH as it is not case sensitive (You can also use FIND if you want to perform a case-sensitive check).
Next, we will use the ISNUMBER function to limit the results only to numeric results - meaning that the text was found.
0 {=ISNUMBER(SEARCH("substitution - on",H4:H23))}
0
1
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
Now, we see that wherever we had numbers, the function returned TRUE!
Finally, we use the FILTER function to filter the data in column C (The names), based on the criteria in column H (look for ro
You may have noticed that we wrote each function only once, instead of repeating it for all the rows.
This is achieved by Excel's ability to "SPILL" cells. This is a new ability that can make your formula-writing experience much
Read more about SPILLED ranges and Dynamic Array Formulas here.
To read more about the SEARCH function and practice it click here!
To read and practice the FIND function click here!
To read more about ISNUMBER (and other IS functions) click here!
to read more abou the FILTER function (and practice, of course...) click here!
3 Return the names of the players that played in more than one position during the game
#NAME? {=_xlfn._xlws.filter(C4:C23,(LEN(H4:H23)-LEN(SUBSTITUTE(H4:H23,"position_id","")))/LE
#NAME?
#NAME?
#NAME?
#NAME?
#NAME?
First, we need to understand what strategy we are going to use in order to find the players who played in more than one p
Let's look at Onyinye Wilfred Ndidi's data:
Now, how do we count the number of occurences of "position_id" for each player's data?
We can do the following trick:
Basically, we check for the length of each text as a whole.
From the length we received, we substract the length of everything except the found occurence(s).
Finally, we divide the length we found which is the total length of all the occurences of the word, by the length of a single
2 {=LEN(H4:H23)}
370
396
200
179
174
175
390
194
2
201
181
2
373
559
357
195
2
2
2
#2 - Check length of everything except the words we are looking for (position_id)
2 {=LEN(SUBSTITUTE(H4:H23,"position_id",""))}
348
374
189
168
163
164
368
183
2
190
170
2
351
526
335
184
2
2
2
The SUBSTITUTE function is used here to replace each occurence of "position_id" with an empty text.
The result we get is the length of everything minus the length of word(s) we were looking for.
Finally, we subtract the lengths to find only the length of the words we were looking for.
To translate the length into number of occurences, we will divide this length by the length of a single word.
0 {=(LEN(H4:H23)-LEN(SUBSTITUTE(H4:H23,"position_id","")))/LEN("position_id")}
2
2
1
1
1
1
2
1
0
1
1
0
2
3
2
1
0
0
0
And finally, we use the FILTER function, we mentioned above, to show only occurences with more than 1 position_id!
#NAME? {=_xlfn._xlws.filter(C4:C23,(LEN(H4:H23)-LEN(SUBSTITUTE(H4:H23,"position_id","")))/LE
#NAME?
#NAME?
#NAME?
#NAME?
#NAME?
4 Return the names of the players that played the entire game (From start to the final whistle, without being substituted)
In this question, we wish to find players that were included in the Starting 11 ("Starting XI"), and that they played until "Fin
As there are two criteria here, we need to multiply these two criteria. The filter function will show only rows where these
In green, we can see the only 8 players that were both in the Starting 11 and played until the Final Whistle.
This make sense to us, as we know that we had 3 substitutions made during the game (11-3=8)
Click here for more information on the usage of FILTER function with multiple criteria
positions
[]
[{'position_id': 15, 'position': 'Left Center Midfield', 'from': '89:40', 'to': '89:47',
'from_period': 2, 'to_period': 2, 'start_reason': 'Substitution - On (Tactical)',
'end_reason': 'Tactical Shift'}, {'position_id': 19, 'position': 'Center Attacking
Midfield', 'from': '89:47', 'to': None, 'from_period': 2, 'to_period': None,
'start_reason': 'Tactical Shift', 'end_reason': 'Final Whistle'}]
[{'position_id': 24, 'position': 'Left Center Forward', 'from': '00:00', 'to': '84:03',
'from_period': 1, 'to_period': 2, 'start_reason': 'Starting XI', 'end_reason':
'Substitution - Off (Tactical)'}]
[{'position_id': 24, 'position': 'Left Center Forward', 'from': '84:03', 'to': '89:47',
'from_period': 2, 'to_period': 2, 'start_reason': 'Substitution - On (Tactical)',
'end_reason': 'Tactical Shift'}, {'position_id': 22, 'position': 'Right Center
Forward', 'from': '89:47', 'to': None, 'from_period': 2, 'to_period': None,
'start_reason': 'Tactical Shift', 'end_reason': 'Final Whistle'}]
[{'position_id': 15, 'position': 'Left Center Midfield', 'from': '00:00', 'to': '89:40',
'from_period': 1, 'to_period': 2, 'start_reason': 'Starting XI', 'end_reason':
'Substitution - Off (Tactical)'}]
(yellow or red), we need to count the entries that are not empty (empty in our example means: [] ).
with the <> operator (not equal). We are basically looking for anything which is not equal to [])
e as substitutes.
C4:C23,ISNUMBER(SEARCH("substitution - on",H4:H23)))}
hat number represents the character position in which "substitution - on" was found in the text.
n't find a match.
can also use FIND if you want to perform a case-sensitive check).
results only to numeric results - meaning that the text was found.
nction returned TRUE!
n column C (The names), based on the criteria in column H (look for rows where "substitution - on" was found in the text).
UMBER(SEARCH("substitution - on",H4:H23)))}
C4:C23,(LEN(H4:H23)-LEN(SUBSTITUTE(H4:H23,"position_id","")))/LEN("position_id")>1)}
ed to achieve here!
oing to use in order to find the players who played in more than one position.
inning as a Right Center Midfield, but then he switched to Center Midfield in 89:47.
nd we can see that the text "position_id" appears twice.
ition_id" as an indicator for playing more than one position during the game.
TE(H4:H23,"position_id","")))/LEN("position_id")}
d above, to show only occurences with more than 1 position_id!
C4:C23,(LEN(H4:H23)-LEN(SUBSTITUTE(H4:H23,"position_id","")))/LEN("position_id")>1)}
cluded in the Starting 11 ("Starting XI"), and that they played until "Final_Whistle".
hese two criteria. The filter function will show only rows where these two criteria are met.
xlws.filter(C4:C23,(ISNUMBER(SEARCH("Starting XI",H4:H23))))}
xlws.filter(C4:C23,(ISNUMBER(SEARCH("Final Whistle",H4:H23))))}
h in the Starting 11 and played until the Final Whistle.
stitutions made during the game (11-3=8)