Covid-19 Analysis on a Map with Python

Folium is a powerful Python library that helps you create several types of maps. The fact that the Folium results are interactive makes this library very useful for dashboard building.

Using the folium map library we will plot the cases of covid 19 in India on a Map.

To get started open you command prompt or terminal if you use pycharm and write- pip install folium

You can download the csv file from here

import pandas as pd
import folium
# Analysis of covid 19
df = pd.read_csv("Covid cases in India.csv")
df.drop(['S. No.'], axis=1, inplace=True)
df['Total Cases'] = df['Total Confirmed cases (Indian National)']+df['Total Confirmed cases ( Foreign National )']
total_cases_overall = df['Total Cases'].sum()
df['Active Cases']= df['Total Cases']-(df['Death']+df['Cured'])
df.style.background_gradient(cmap='Reds')
Total_Active_Cases = df.groupby('Name of State / UT')['Total Cases'].sum().sort_values(ascending=False).to_frame()
Total_Active_Cases.style.background_gradient(cmap='Reds')
# Plotting on map
map = folium.Map(location=[30, 70], zoom_start=5, tiles='Stamenterrain')
for lat, long, value, name in zip(df_full['Latitude'],
                                  df_full['Longitude'], df_full['Total Cases'],
                                  df_full['Name of State / UT']):
    folium.CircleMarker([lat, long], radius=value*0.03, popup=('<strong>State</strong>: '
                                                              +str(name).capitalize()+'<br>''<strong>Total Cases</strong>:'
                                                              +str(value)+ '<br>'),
                        color='red',fill_color='red', fill_opacity=0.1).add_to(map)
map.save('newmap.html')

Aman Kharwal
Aman Kharwal

I'm a writer and data scientist on a mission to educate others about the incredible power of data📈.

Articles: 1431

2 Comments

  1. Hello, nice tutorials. I tried running the code however I get the error… NameError: name ‘df_full’ is not defined

Leave a Reply