Let’s Do Some Data – I: Simple Analysis of Local Bodies in Nepal

The Feature Image was taken from OnlineKhabar

Baisakh 31, 2074 B.S(May 14, 2017) i.e Today is an important day for Nepal and Nepalese people. Today we are having the election of local bodies after two decades under the new constitution crafted by the people of Nepal.

Nepal is governed according to the Constitution which came into effect on 2072/06/03 B.S (Sept 20, 2015). According to this Nepal’s administrative division was revised. To choose the leaders for these revised local bodies today’s election is taking place. Out of seven states, the election is taking place in three states. In rest of the states, the election will take place in another round most likely a month later from today. And this post is in a way about this election. This post is not about the political aspect of this election rather it is about the how we can perform simple analysis of data related to this election.

As mentioned in my previous post, to perform analysis on data we need the data that is relevant to us. The data may or may not be available in the form we want. For the analysis purpose data available in  Open Format like CSV, JSON, XML etc. Luckily for us, we do not need to collect data ourselves, ElectioNepal by Open Knowledge Nepal in collaboration with Code for Nepal. They provide data relevant to the election. Here, I have taken the dataset that has information on a number of local bodies per district. Local bodies mean NargarPalika(Municipality), MahanagarPalika(Metropolitan city), UpaMahanagraPalika (Sub-Metropolitan city) and GauhPalika(Village Committee).

I have used Python programming language including matplotlib and numpy library. First of all, we need to import the required libraries and load the CSV file. The code below does exactly that

#Importing the libraries that are necessary for the data analysis
import csv
import matplotlib.pyplot as plt
import numpy as np

Now we need to import the CSV file. The code below can be used for loading the data into the program.

#Let's say we saved the CSV file as 'localBodyNepal.csv'. Then we can load it as.
with open('localBodyNepal.csv') as csvfile:

If we print out the variable localbody_nepal we will see how our data is loaded into the program. The image below is the sneak peak into our data.

Sneak Peak of DataSet

Now, we can do a lot of things once the data is loaded. For an example, we can create a bar graph that shows the distribution of  702 local bodies across 75 districts in Nepal. The code below plots a graph. The x-axis on the graph is different Districts in Nepal and the y-axis represents a number of local bodies in each district.

districts=(list(d['District'] for d in nepal))
dic =list(range(1,76))
total=((list(int(d['Total Local Body']) for d in nepal)))

Let’s have a look at the bar graph produced by the code above


We can see that on an average each district about nine local bodies. Let’s use the python code to verify

#Calculating the average number of local bodies per district.
print("There are on average "+str(average_local_body)+" per district")

We get the following result result

There are on average 9.36 per district

Now let’s make a pie chart that shows the percentage of the different local body. We will use the code below:

gaupalika=((list(int(d['Gaupalika']) for d in nepal)))
nagarpalika=(list(int(d['Nagarpalika'])for d in nepal))
upaMahanarpalika=(list(int(d['Upa Mahanarpalika']) for d in nepal))
mahanarpalika=(list(int(d['Mahanarpalika']) for d in nepal))


labels = ['Gaupalika', 'Nagarpalika', 'Upa Mahanarpalika', 'Mahanarpalika']
sizes = [noOfGaupalika,noOfNagarpalika,noOfUpaMahanarpalika,noOfmahanarpalika]
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']

pie = plt.pie(sizes, labels=labels,shadow=False, autopct='%1.1f%%')
plt.legend(pie[0], labels)

We can see the distribution of each type of local body in Nepal from the pie chart that us shown below:


Type of Local Body

We can perform various other analysis like the number of GauPalika, Nagarpalika, Upa- MahanagarPalika and MahanagarPalika per district by following the similar process that was used to analyze the total local bodies.

Let’s hope that leaders of the local bodies elected from today’s election will work for the welfare of the people in their constituents. Next time we will do some more interesting analysis.

The complete data set and code is available on the GitHub Repo.




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: