This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
martindaniel4
committed
Apr 25, 2015
1 parent
282f187
commit cd956cf
Showing
6 changed files
with
5,276 additions
and
11 deletions.
There are no files selected for viewing
185 changes: 185 additions & 0 deletions
185
s4/.ipynb_checkpoints/04 - Visualiser des données géographiques avec Folium-checkpoint.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
{ | ||
"metadata": { | ||
"name": "", | ||
"signature": "sha256:6730aed8c27e8e9cbdcc5ae324c9f219f241c468139079d76df452fbbbd9a22e" | ||
}, | ||
"nbformat": 3, | ||
"nbformat_minor": 0, | ||
"worksheets": [ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "heading", | ||
"level": 1, | ||
"metadata": {}, | ||
"source": [ | ||
"Visualiser des donn\u00e9es g\u00e9ographiques avec la librairie Folium" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Pouvoir repr\u00e9senter une carte est souvent une composante essentielle d'une analyse de donn\u00e9es. \n", | ||
"\n", | ||
"La librairie **Folium** permet de cr\u00e9er facilement des cartes interactives. Vous pouvez en lire plus sur la documentation officielle - https://www.pypi.python.org/pypi/folium\n", | ||
"\n", | ||
"Dans cette partie, vous verrez : \n", | ||
"\n", | ||
"- Comment int\u00e9grer une carte interactive au sein de l'environnement iPython\n", | ||
"- Comment tracer des points \u00e0 partir d\"un DataFrame \n", | ||
"- Comment tracer des zones, en utilisant des rep\u00e8res TopoJSON" | ||
] | ||
}, | ||
{ | ||
"cell_type": "heading", | ||
"level": 2, | ||
"metadata": {}, | ||
"source": [ | ||
"Cr\u00e9er des cartes et des rep\u00e8res" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Installez la librairie folium depuis votre terminal gr\u00e2ce \u00e0 pip : " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"collapsed": false, | ||
"input": [ | ||
"pip install folium" | ||
], | ||
"language": "python", | ||
"metadata": {}, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Nous importons tout d'abord la librairie folium ainsi que le module HTML de iPython :" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"collapsed": false, | ||
"input": [ | ||
"import folium\n", | ||
"from IPython.display import HTML" | ||
], | ||
"language": "python", | ||
"metadata": {}, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Nous d\u00e9finissons ensuite une fonction **inline_map** qui renvoie un iframe HTML pouvant s'int\u00e9grer au sein de notre document iPython" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"collapsed": false, | ||
"input": [ | ||
"def inline_map(map):\n", | ||
" map._build_map()\n", | ||
" return HTML('<iframe srcdoc=\"{srcdoc}\" style=\"width: 100%; height: 510px; border: none\"></iframe>'.format(srcdoc=map.HTML.replace('\"', '"')))" | ||
], | ||
"language": "python", | ||
"metadata": {}, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Nous d\u00e9finissons les param\u00e8tres d'affichage de notre carte en pr\u00e9cisant son centre et le zoom \u00e0 utiliser :" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"collapsed": false, | ||
"input": [ | ||
"map = folium.Map(location=[48.8655909,2.378983], zoom_start=6)" | ||
], | ||
"language": "python", | ||
"metadata": {}, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"collapsed": false, | ||
"input": [ | ||
"inline_map(map)" | ||
], | ||
"language": "python", | ||
"metadata": {}, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "heading", | ||
"level": 2, | ||
"metadata": {}, | ||
"source": [ | ||
"Cr\u00e9er des rep\u00e8res \u00e0 partir d'une DataFrame" | ||
] | ||
}, | ||
{ | ||
"cell_type": "heading", | ||
"level": 2, | ||
"metadata": {}, | ||
"source": [ | ||
"Cr\u00e9er des zones \u00e0 partir de fichiers GeoJSON" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"collapsed": false, | ||
"input": [ | ||
"import pandas as pd" | ||
], | ||
"language": "python", | ||
"metadata": {}, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"collapsed": false, | ||
"input": [ | ||
"mcdo = pd.read_csv(\"data/McDonalds_Fr.csv\",encoding='latin-1')" | ||
], | ||
"language": "python", | ||
"metadata": {}, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"collapsed": false, | ||
"input": [ | ||
"for x in mcdo.values:\n", | ||
" location = []\n", | ||
" location.append(x[1])\n", | ||
" location.append(x[0])\n", | ||
" map.circle_marker(location,radius=4,fill_color='red',popup=x[2])" | ||
], | ||
"language": "python", | ||
"metadata": {}, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"collapsed": false, | ||
"input": [], | ||
"language": "python", | ||
"metadata": {}, | ||
"outputs": [] | ||
} | ||
], | ||
"metadata": {} | ||
} | ||
] | ||
} |
Oops, something went wrong.