Generate Interactive Maps using Folium in Python

Using the Folium Library in Python we can easily Plot Geographical data on a Map. Your analysis will be much more valuable if you visualized them the right way. A perfectly visualized data helps in drawing the changes and trends for further exploration or for making conclusions.

To simplify the use of Geographical visualisation of data you can use the Folium library available in the virtual environment of Python. The best thing about python is that it provides a large number of libraries for almost every framework in its virtual environment.

Folium is a powerful Python library that is built on Javascript and helps you in creating a geographical visualization of data in python. Folium is not available by default in the virtual environment of python. But it can be easily installed in your environment like other libraries, using the command – pip install folium.

Generate Interactive Maps using Folium

In this article, I will show you how we can generate geographical data using the folium library in python. I will plot the Indian Cricket Stadiums on a Map using the data of Indian cricket stadiums.

You can download the required CSV file from below:

Importing Required Modules:

import folium
import pandas as pd
data = pd.read_csv("stadium.csv", encoding="cp1252")
latitude = list(data['LAT'])
longitude = list(data['LON'])
name = list(data["NAME"])
capacity = list(data["capacity"])
website = list(data["website"])
picture = list(data['picture'])
f = folium.FeatureGroup("my map")
for lt, ln, nm, cp, ws, pic in zip(latitude, 
                                   longitude, name, 
                                   capacity, website, picture):
    f.add_child(folium.Marker(location=[lt, ln], 
                              popup="<b>name   : </b>"+nm+ 
                                    "<br> <b>capacity  "
                                    ": </b>"+str(cp)+""
                                    "<br><b>wikipidea "
                                                     "link: </b><a href="+ws+">"
                            "click here</a>"+"<br> <img src="+pic+" "
                            "height=142 width=290>",icon=folium.Icon(color="green")))
map = folium.Map(location=[21.1458,79.0082],zoom_start=5)

Upon running the above code our map will look like that one below, you can see how easy it is use generate a map using the folium library of python.

In this way, you can generate these amazing geographical data with the help of folium library in python.

Default image
Aman Kharwal

I am a programmer from India, and I am here to guide you with Data Science, Machine Learning, Python, and C++ for free. I hope you will learn a lot in your journey towards Coding, Machine Learning and Artificial Intelligence with me.

Leave a Reply