In [3]:
#Load DataSet
import folium
import pandas as pd

In [4]:
grants_data = pd.read_pickle('P3_Cantons_Sum.pickle')
grants_data['Canton Shortname'] = grants_data.index
grants_data = grants_data.reset_index(drop=True)
grants_data.columns = ['Total Amount','Canton']
grants_data


Out[4]:
Total Amount Canton
0 2.269557e+08 AG
1 1.653339e+09 BE
2 1.395041e+09 BS
3 4.590737e+08 FR
4 1.888685e+09 GE
5 1.834294e+06 GR
6 1.484494e+08 LU
7 3.832046e+08 NE
8 9.076450e+07 SG
9 1.766910e+05 SH
10 3.416297e+07 SO
11 9.365510e+05 SZ
12 1.526446e+06 TG
13 3.022581e+07 TI
14 2.447783e+09 VD
15 2.260860e+07 VS
16 4.957150e+05 ZG
17 3.919900e+09 ZH

In [8]:
topo_path = r'world-countries.json'
topo_path


Out[8]:
'world-countries.json'

In [18]:
topo_path2=r'ch-cantons.topojson.json'
topo_path2


Out[18]:
'ch-cantons.topojson.json'

In [12]:
ch_map = folium.Map(location=[46.8769, 8.6017], tiles='Mapbox Bright',
                    zoom_start=7)
ch_map


Out[12]:
Now Map Switzerland with Canton Divisions

In [22]:



---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/Users/catarinaneves/anaconda/lib/python3.5/site-packages/IPython/core/formatters.py in __call__(self, obj)
    309             method = get_real_method(obj, self.print_method)
    310             if method is not None:
--> 311                 return method()
    312             return None
    313         else:

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/map.py in _repr_html_(self, **kwargs)
    177             self._parent = None
    178         else:
--> 179             out = self._parent._repr_html_(**kwargs)
    180         return out
    181 

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/element.py in _repr_html_(self, **kwargs)
    367 
    368         """
--> 369         html = self.render(**kwargs)
    370         html = "data:text/html;base64," + base64.b64encode(html.encode('utf8')).decode('utf8')  # noqa
    371 

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/element.py in render(self, **kwargs)
    357         """Renders the HTML representation of the element."""
    358         for name, child in self._children.items():
--> 359             child.render(**kwargs)
    360         return self._template.render(this=self, kwargs=kwargs)
    361 

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/element.py in render(self, **kwargs)
    665 
    666         for name, element in self._children.items():
--> 667             element.render(**kwargs)

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/features.py in render(self, **kwargs)
    478     def render(self, **kwargs):
    479         """Renders the HTML representation of the element."""
--> 480         super(TopoJson, self).render(**kwargs)
    481 
    482         figure = self.get_root()

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/element.py in render(self, **kwargs)
    661         script = self._template.module.__dict__.get('script', None)
    662         if script is not None:
--> 663             figure.script.add_children(Element(script(self, kwargs)),
    664                                        name=self.get_name())
    665 

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/jinja2/runtime.py in __call__(self, *args, **kwargs)
    434             raise TypeError('macro %r takes not more than %d argument(s)' %
    435                             (self.name, len(self.arguments)))
--> 436         return self._func(*arguments)
    437 
    438     def __repr__(self):

<template> in macro(l_this, l_kwargs)

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/jinja2/runtime.py in call(_Context__self, _Context__obj, *args, **kwargs)
    194                 args = (__self.environment,) + args
    195         try:
--> 196             return __obj(*args, **kwargs)
    197         except StopIteration:
    198             return __self.environment.undefined('value was undefined because '

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/features.py in style_data(self)
    471             else:
    472                 return data
--> 473         geometries = recursive_get(self.data, self.object_path.split('.'))['geometries']  # noqa
    474         for feature in geometries:
    475             feature.setdefault('properties', {}).setdefault('style', {}).update(self.style_function(feature))  # noqa

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/features.py in recursive_get(data, keys)
    468         def recursive_get(data, keys):
    469             if len(keys):
--> 470                 return recursive_get(data.get(keys[0]), keys[1:])
    471             else:
    472                 return data

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/features.py in recursive_get(data, keys)
    468         def recursive_get(data, keys):
    469             if len(keys):
--> 470                 return recursive_get(data.get(keys[0]), keys[1:])
    471             else:
    472                 return data

AttributeError: 'NoneType' object has no attribute 'get'
Out[22]:
<folium.folium.Map at 0x114d64a20>

In [23]:
ch_map.choropleth(geo_path=topo_path2, data=grants_data,
             columns=['Canton', 'Total Amount'],
             key_on='objects.cantons.id',
             fill_color='YlGn', fill_opacity=0.7, line_opacity=0.2,
             legend_name='Total Grants (CHF)')
ch_map


/Users/catarinaneves/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:5: FutureWarning: 'threshold_scale' default behavior has changed. Now you get a linear scale between the 'min' and the 'max' of your data. To get former behavior, use folium.utilities.split_six.
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/Users/catarinaneves/anaconda/lib/python3.5/site-packages/IPython/core/formatters.py in __call__(self, obj)
    309             method = get_real_method(obj, self.print_method)
    310             if method is not None:
--> 311                 return method()
    312             return None
    313         else:

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/map.py in _repr_html_(self, **kwargs)
    177             self._parent = None
    178         else:
--> 179             out = self._parent._repr_html_(**kwargs)
    180         return out
    181 

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/element.py in _repr_html_(self, **kwargs)
    367 
    368         """
--> 369         html = self.render(**kwargs)
    370         html = "data:text/html;base64," + base64.b64encode(html.encode('utf8')).decode('utf8')  # noqa
    371 

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/element.py in render(self, **kwargs)
    357         """Renders the HTML representation of the element."""
    358         for name, child in self._children.items():
--> 359             child.render(**kwargs)
    360         return self._template.render(this=self, kwargs=kwargs)
    361 

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/element.py in render(self, **kwargs)
    665 
    666         for name, element in self._children.items():
--> 667             element.render(**kwargs)

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/features.py in render(self, **kwargs)
    478     def render(self, **kwargs):
    479         """Renders the HTML representation of the element."""
--> 480         super(TopoJson, self).render(**kwargs)
    481 
    482         figure = self.get_root()

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/element.py in render(self, **kwargs)
    661         script = self._template.module.__dict__.get('script', None)
    662         if script is not None:
--> 663             figure.script.add_children(Element(script(self, kwargs)),
    664                                        name=self.get_name())
    665 

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/jinja2/runtime.py in __call__(self, *args, **kwargs)
    434             raise TypeError('macro %r takes not more than %d argument(s)' %
    435                             (self.name, len(self.arguments)))
--> 436         return self._func(*arguments)
    437 
    438     def __repr__(self):

<template> in macro(l_this, l_kwargs)

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/jinja2/runtime.py in call(_Context__self, _Context__obj, *args, **kwargs)
    194                 args = (__self.environment,) + args
    195         try:
--> 196             return __obj(*args, **kwargs)
    197         except StopIteration:
    198             return __self.environment.undefined('value was undefined because '

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/features.py in style_data(self)
    471             else:
    472                 return data
--> 473         geometries = recursive_get(self.data, self.object_path.split('.'))['geometries']  # noqa
    474         for feature in geometries:
    475             feature.setdefault('properties', {}).setdefault('style', {}).update(self.style_function(feature))  # noqa

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/features.py in recursive_get(data, keys)
    468         def recursive_get(data, keys):
    469             if len(keys):
--> 470                 return recursive_get(data.get(keys[0]), keys[1:])
    471             else:
    472                 return data

/Users/catarinaneves/anaconda/lib/python3.5/site-packages/folium/features.py in recursive_get(data, keys)
    468         def recursive_get(data, keys):
    469             if len(keys):
--> 470                 return recursive_get(data.get(keys[0]), keys[1:])
    471             else:
    472                 return data

AttributeError: 'NoneType' object has no attribute 'get'
Out[23]:
<folium.folium.Map at 0x114d64a20>

In [ ]:


In [ ]:


In [ ]: