Related Articles

Related Articles

Plotting ICMR approved test centers on Google Maps using folium package
  • Last Updated : 22 Jun, 2020

Folium is a powerful data visualization library in Python that was built primarily to help people visualize geospatial data. With Folium, a map of any location in the world can be created as long as its latitude and longitude values are known. Also, the maps created by Folium are interactive in nature, so that you can zoom in and out after the map is rendered, which is a very useful feature. Folium builds on the Python ecosystem’s data wrangling powers and the Leaflet.js library’s mapping powers. In Python, the data is manipulated and then visualized via folium on a Leaflet map.


Before you can use Folium, you may need to install it on the system using either of the two methods below.

$ pip install folium


$ conda install -c conda-forge folium

We’ll be working with the ICMR dataset which has 7 columns: lab, address, Pincode, city, state, type, latitude, and longitude. We will be using the ‘ICMRTestingLabsWithCoords.csv’ file in the dataset. To download the dataset click here.

Getting Started

Importing required libraries

import folium
import pandas as pd

Importing dataset

df = pd.DataFrame(pd.read_csv(‘ICMRTestingLabsWithCoords.csv’))

For focusing the window only on India. We pass India’s coordinates along with zoom Parmenter to folium.Map().

phone_map = folium.Map(location = [20.5937, 78.9629], 

Making the Marker

To display name and type of laboratory whether it is private or government-based. Also, to pass the coordinates of the markers, we will be writing a Python code for it.

locate = {}
for i, j, k, l in zip(df['latitude'], 

    temp.extend((i, j))
    marker = folium.Marker(location = locate['loc'], 
                           popup = str(k)+' Type:'+str(l))

We will be running a for loop through 4 columns ‘latitude’, ‘longitude’, ‘lab and ‘type’. First, we create a ‘temp’ list which holds latitude and longitude of the particular labs as we traverse through all. This particular latitude and longitude list are then passed to a dictionary locate. Now we create a marker by calling ‘.Marker ‘ from the folium and passing in the locate dictionary to location and popup takes lab name and type of lab in string format. The type of marker is ‘’. Finally we call ‘.add_to’ off of the marker and passing in the phone_map. Now that our pins are ready it’s time to display the plotted pins. We do that by calling phone_map.


Full Code:






import folium
import pandas as pd
phone_map = folium.Map(location=[20.5937, 78.9629],
df = pd.DataFrame(pd.read_csv('ICMRTestingLabsWithCoords.csv'))
locate = {}
for i, j, k, l in zip(df['latitude'], df['longitude'],
                      df['lab'], df['type']):
    temp = []
    temp.extend((i, j))
    locate['loc'] = temp
    marker = folium.Marker(location=locate['loc'],
                           popup=str(k)+' Type:'+str(l))



Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :