Mapping location of air quality sensing in India ¶
In this notebook, I'll show a quick example of how to use Folium (which internally uses LeafletJS) for visualising the location of air quality monitors in India. The purpose of this notebook is eductional in nature.
Standard Imports ¶
In [1]:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
%matplotlib inline
Downloading data from OpenAQ for 2018-04-06 ¶
In [2]:
!wget --no-check-certificate https://openaq-data.s3.amazonaws.com/2018-04-06.csv -P /Users/nipun/Downloads/
In [3]:
import pandas as pd
df = pd.read_csv("/Users/nipun/Downloads/2018-04-06.csv")
df = df[(df.country=='IN')&(df.parameter=='pm25')].dropna().groupby("location").mean()
In [4]:
df
Out[4]:
Downloading World GeoJson file ¶
In [6]:
!wget --no-check-certificate https://raw.githubusercontent.com/python-visualization/folium/master/examples/data/world-countries.json
Creating india.json correspdonding to Indian data ¶
In [7]:
import json
e = json.load(open('world-countries.json','r'))
json.dump(e['features'][73], open('india.json','w'))
In [8]:
import folium
folium_map = folium.Map(width = '60%',height=800,location=[20, 77],
zoom_start=5,
tiles="Stamen Terrain",min_lat=7, max_lat=35, min_lon=73, max_lon=90)
for x in df.iterrows():
name = x[0]
lat, lon = x[1]['latitude'], x[1]['longitude']
folium.CircleMarker([lat, lon], radius=5, color='#000000',fill_color='#D3D3D3' , fill_opacity=1).add_to(folium_map)
folium.GeoJson('india.json').add_to(folium_map)
folium_map
Out[8]:
There you go!