Sunday, 16 September 2018

Berlin stats and maps

I created a while ago a map with number of Spaniards in Berlin on each administrative planning area (Berlin is divided in some 450 areas which are called LOR (Lebensweltlich orientierte Räume), i.e. way more granularity than postal code). But I was not fully satisfied with that solution. So, let´s go through a second approach using bokeh. And why bokeh? Well, because my company has given me access to datacamp and, among other things, I recently did a course called Interactive Data Visualization with Bokeh. But since I learn better when doing a mini-project, rather than just going through the videos and exercises, I thought this would be fun.

First of all, I needed to find a way to plot the planning areas. This is easy enough, as Berlin has a site where the info can be downloaded as a kmz file (zipped kml files). Once unzipped, it is relatively straight forward to read the information with the coordinates for each area. However the amount of detail of the areas is just too high, with hundreds of points used for each contour. So the first hurdle was to simplify the contours of each area. As it happens, there is a python library which does exactly this. It´s appropriately called rdp as it is an implementation of the Ramer-Douglas-Peucker Algorithm (I had never heard of it until a few days). After playing a bit with it, I managed to reduce the number of coordinates used by a factor of 5 and still retain more than enough detail for the plot.

Then it was required to aggregate the statistical information from the statistical office for Berlin and Brandenburg so that the colour would be proportional to the amount of residents in the area. White if zero Spaniards live in an area and black if 300 or more live there. For info, I believe each area is supposed to have ~7500 people. And therefore the map also shows density of  (total) population in Berlin, i.e. smaller areas are very densely populated.

The visualization is nicer if you can hover the map and see name of the planning area and the population. And to bring it a notch higher, it is even nicer if you can choose the date of the report from a dropdown menu. When you make a selection, the data is updated and new colors and information are shown when hovering. The result is shown below (unfortunately not interactive in this post, as I run it in my computer with a local bokeh server)


Sunday, 9 September 2018

Españoles en Alemania (2017)

El servicio estadístico alemán publica anualmente el informe sobre población extranjera en Alemania. Los últimos datos disponibles son los de diciembre de 2017. Siguiendo la pequeña tradición de los últimos años, aquí va la entrada analizando los datos actuales de los españoles.

El ritmo de crecimiento del número de españoles parecía haberse estancado en 2016 pero ha rebotado, y con fuerza, en el 2017. Si en el 2016 la población española subió en 7,500 personas, en el 2017 la subida ha sido de casi 15,000 más. Y parece que casi todos han elegido Berlín como residencia, que sube de apenas diez mil españoles a más de 22,000, más que duplicando la presencia española en la capital en un sólo año. Sin embargo, otro servicio estadístico alemán, el Amt für Statistik Berlin-Brandenburg, cifra el número de españoles en Berlín a finales de 2017 en algo menos de quince mil, es decir, similar a municipios como El Escorial, Tarancón, Arnedo, Azpeitia o Villaviciosa.


  2017 Diferencia con 2016
  Total 2015 Hombres Mujeres Total Hombres Mujeres
Baden-Württemberg 25195 12995 12200 -10 -10 0
Bayern 21870 11185 10690 -185 -65 -115
Berlin 22405 11335 11065 12695 6540 6150
Brandenburg 925 510 415 -95 -50 -45
Bremen 2235 1185 1050 -70 -45 -25
Hamburg 5915 2975 2940 0 0 0
Hessen 25585 13310 12275 530 250 280
Mecklenburg-Vorpommern 820 440 380 -70 -50 -20
Niedersachsen 11785 6240 5550 15 5 15
Nordrhein-Westfalen 48015 25145 22870 1415 795 615
Rheinland-Pfalz 5655 2925 2730 65 20 45
Saarland 1035 490 545 45 35 15
Sachsen 2040 1115 920 30 25 0
Sachsen-Anhalt 595 340 255 -60 -35 -25
Schleswig-Holstein 2955 1560 1395 100 40 60
Thüringen 975 615 365 45 20 30