In Mexico, we were just recently enabled the posibility for independent candidates to be present in all elections. There are, naturally, some prereqs for them to appear in the ballot. In the case I'm interested, that of my hometown, the requirement is to have at least the signatures of at least 3% of the municipality's registered voters, representing at least 50% of the electoral sections (secciones in Spanish) by having at least 2% of each section.

In this post I will fetch and plot all electoral sections from Ciudad Juarez, Mexico. Then I will plot, from the results of the 2013 election, the number of registered voters in each section. The goal in this post is to identify:

  • First the individual secciones that the independent candidates must consider.
  • Then traits that might hint that specific sections are easier to get than others. These traits, in my opinion, can be total number of registered voters (we want the lowest number of voters, since every section counts the same and we need 2% of the registered voters to be able to count a section), density (the area of the sections varies a lot, so we want denser sections to increase or chance of finding voters)

Plotting the electoral sections from Juarez

I obtained from this resource the shapefiles for all of Mexico's electoral sections. I will filter out those that actually belong to Juarez, the municipality under consideration, and plot them to get an idea of what we are dealing with.

In [1]:
import geopandas
import pandas as pd
import os
In [2]:
assets = '/'.join(os.getcwd().split('/')[:-1] + ['assets'])
path = (assets + '/{}').format
secciones_mexico = geopandas.GeoDataFrame.from_file(path('secciones-inegi/secciones.shp'))

Now let's check what the columns are..

In [3]:
secciones_mexico.columns
Out[3]:
Index([  u'CLAVEGEO',   u'DISTRITO',    u'ENTIDAD',   u'GRAPROES',
       u'GRAPROES_F', u'GRAPROES_M',   u'HOGJEF_F',   u'HOGJEF_M',
          u'MUN_IFE',  u'MUN_INEGI',
       ...
           u'VPH_PC', u'VPH_PISODT', u'VPH_PISOTI',  u'VPH_RADIO',
        u'VPH_REFRI', u'VPH_SNBIEN', u'VPH_S_ELEC',  u'VPH_TELEF',
           u'VPH_TV',   u'geometry'],
      dtype='object', length=197)

What we want is the municipality, let's get only those that are from Juarez (from my IFE card I can see that Juarez is 037), we also want the state, in this case 8.

In [4]:
# for some reason, the dataset uses integers instead of strings
# which means that 037 becomes 37
secciones_juarez = secciones_mexico[secciones_mexico['MUN_IFE'] == 37][secciones_mexico['ENTIDAD'] == 8]
/home/ramon/development/notebooks/venv/local/lib/python2.7/site-packages/pandas/core/frame.py:1997: UserWarning: Boolean Series key will be reindexed to match DataFrame index.
  "DataFrame index.", UserWarning)
In [5]:
secciones_juarez['ENTIDAD'].unique()
Out[5]:
array([8])
In [6]:
len(secciones_juarez)
Out[6]:
1120

This coincides with external checks. At this point we've fetched our set to include only the sections that belong to Ciudad Juarez, we can go ahead and plot it.

At this point, I'll store the filtered sections into a JSON file to be uploaded to MapBox so we can better manage viewing that many polygons.

In [7]:
secciones_centroids = secciones_juarez.copy()
In [8]:
secciones_centroids['geometry'] = secciones_centroids.centroid
In [9]:
secciones_juarez['SECCION_STR'] = secciones_juarez['SECCION'].astype(int).astype(str)
In [10]:
# first import folium
import folium

# now let's convert our GeoDataFrame into a GeoJson
sj_gjson = secciones_juarez.to_crs(epsg='4326').to_json()

mapa = folium.Map(location=[31.7394, -106.4869], zoom_start=11)
In [11]:
mapa.geo_json(geo_str=sj_gjson, data=secciones_juarez,
               columns=['SECCION_STR', 'POBTOT'],
               key_on='feature.properties.SECCION_STR',
               fill_color='YlOrRd', fill_opacity=0.7, line_opacity=0.3, reset=True)
In [12]:
mapa
Out[12]: