Visualizing Crime against Women in India on a Map in Python

In this tutorial, we will see how to create a map to visualise crime against women in India in Python programming. We will create what is known as a choropleth map. A choropleth map is a map that is divided into various regions having different intensities in colour based on a parameter. Examples of such parameters are population, per-capita income, etc. Here, we will create a map that indicates the number of crimes against women in the various States and Union Territories of India.

We will implement this in Python with the help of the geopandas and pandas libraries.

Datasets used in this project

Please make sure that the program has access to all 5 of these files inside this zip. Unzip it to use. If you are using Google Colab, please upload them to the files section.

The numbers for violent crime against women in India is based on the data from the Government of India in the year 2014.
(from data.gov.in)

Libraries used in this project

We make use of PyShp, NumPy, Pandas and Plotly Python libraries. We also use the help of Mapbox. I did this project in Google Colab where all these are readily available and need not be installed.

We use Pandas as we will be working with data in the form of Dataframes.

We will need to, however, install the GeoPandas library to work with the creation of maps. This is not pre-installed in Colab.
GeoPandas depends on the Descartes library and this too needs to be installed explicitly.

We can do this with the help of ‘pip install’ statements as shown below.

!pip install geopandas
!pip install descartes

Implementation in Python

  1. We import the necessary libraries.
  2. Next, we read in the necessary files.
  3. We then, merge the dataframes based on the names of States and Union Territories.
  4. Finally, we plot the merged file as a choropleth map of the required size.

Below is our Python code for visualizing the crime against women on India map:

# importing the geopandas and pandas libraries
import geopandas as gpd
import pandas as pd

# reading in the 2 files
# the .csv file contains the data
# the shp file contains the shapes required for the map
data_df = pd.read_csv('Crimes against women Statewise.csv')
map_df = gpd.read_file("Indian_States.shp")

# I changed the name of a column for convenience
map_df.rename(columns = {'st_nm':'States/UTs'}, inplace = True)

# merging the dataframes based on the 'States/UTs' column
merged_df = map_df.set_index('States/UTs').join(data_df.set_index('States/UTs')) 

# Plotting the Choropleth map
merged_df.plot('Total Crimes against Women', figsize = (16, 9), legend = True)

Below is the output image we can see after running our program:

Crime against Women in India on a Map in Python

Conclusion

In this tutorial, we saw how to Visualise crime against Women in India on a simple map. We implemented this choropleth map in Python with the help of the GeoPandas library.

We can add more features for the plot with the help of the matplotlib library if we feel the need to so.

Leave a Reply