I love watching the World Cup: It’s more soccer than you could hope for, mixed with national rivalries. What could be better. Now that I am older than most of the players, it dawned on me the intense pressure that they are under, to perform for their country and a question came to me: Just how old are this kids? Let’s find out.
With a quick google search, I came up with what seemed like a good source of data for the task at hand. I simply copy and pasted the data from my browser into a text editor to get a file that looks like this:
1 2 3 4 5 6 7 8 9 10 11
Cutting and Slicing
Using the power of unix pipes, we can easily extract the data we want from the data. Let’s start by getting all birthdates:
1 2 3 4 5 6 7 8 9 10 11 12
As the man pages say:
cut cut out selected portions of each line of a file. In our case, we want the 3rd field in the database.
Now, we can cut again to get the birth year of each player:
1 2 3 4 5 6 7 8 9 10 11 12
In this case, we are cutting again, this time using
/ as a delimiter. Now we have a list of all the players' birth years.
I searched around for some quick utilities that would generate a histogram and the most promising seemed a python utility called data hacks. Unfortunetly, I did not install for me and I didn’t have the inclination to mess with my python installation. I did however, find something similar to what I needed in a blog post about visualizing your shell history. After adapting it a bit to my purposes, I created a small bash function that now lives in my profile:
1 2 3
This function leverages
awk very heavily.
awk is a pattern-directed scanning and processing language. I am not very familiar with it, but after seeing how powerful it is, I am definitely want to get acquainted with it.
With this function, we can now get a full histogram:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
Notice that the final sort is needed, because
histogram returns the values ordered by the number of times it appeared in the data, but since we are talking about birth years, I believe the graph is more telling if it is in ascending order.
With all that in place, it is relatively easy to make a histogram of other data. I remember Malcom Gladwell’s theory in his book Outliers about how most professional hockey players are born in the first part of the year, because of how the developmental leagues work in Canada. With a database of 735 professional soccer players, chosen to be then best 23 of each country, I would expect 61.25 players to be born on each month. Let’s find out how many really are:
1 2 3 4 5 6 7 8 9 10 11 12 13
Notice that to arrive at this graph, the only thing we changed was the field we extracted from the data, in this case the month of the birthday. Is there a trend here? It does suggest that players born in the first part of the year are favored, but I do not know if it’s statistically significant.
Quick and dirty data analysis on the command line is pretty easy if you know a bit of unix and some awk!