Choropleth Maps in Python

Choropleth maps are a great way to represent geographical data. I have done a basic implementation of two different data sets. I have used jupyter notebook to show the plots.

World Power Consumption 2014

First do Plotly imports
import plotly.graph_objs as go
from plotly.offline import init_notebook_mode,iplot
init_notebook_mode(connected=True)

Next step is to fetch the dataset, we’ll use Python pandas library to read the read the csv file

import pandas as pd
df = pd.read_csv('2014_World_Power_Consumption')

Next, we need to create data and layout variable which contains a dict

data = dict(type='choropleth',
locations = df['Country'],
locationmode = 'country names', z = df['Power Consumption KWH'],
text = df['Country'], colorbar = {'title':'Power Consumption KWH'},
colorscale = 'Viridis', reversescale = True)

Let’s make a layout

layout = dict(title='2014 World Power Consumption',
geo = dict(showframe=False,projection={'type':'Mercator'}))

Pass the data and layout and plot using iplot

choromap = go.Figure(data = [data],layout = layout)
iplot(choromap,validate=False)

The output will be be like below:

Check github for full code.

In next post I will try to make a choropleth for a different data set.

 References: 

https://www.udemy.com/python-for-data-science-and-machine-learning-bootcamp

      https://plot.ly/python/choropleth-maps/

Web development: LAMP: which programming languages should be used: Some thoughts

Now a days people keep asking which technology stack to be used for web development (LAMP, Java, Microsoft) and finally which programming language mainly server-side. Most of the expert says that use whichever you like and comfortable and I totally agree. If you intend to use Java and Microsoft based env then you don’t have much choice but if you are using LAMP stack then you have a lot of options so question again arises which language should be used? Again, I personally think that decision should mainly on based on the requirement, experience, comfort, team etc. Still here is my take based on my little own experiences working with languages:

Perl:
Pros: Old fellow still widely used, Very powerful, secure, well tested over the years in web dev, very good market repo among users, huge collection of open source libraries, new framework like Dancer, Mojolicious are positive sign.
Cons: Difficult to maintain (dirty syntax etc), Hard to get resources, industry is not very positive about its future versions.

Python:
Pros: Powerful, widely used in handling scientific data, academics, analytics, system administrators, Market sentiment is positive, Very good framework like Django.
Cons: Less flexible, performance issues mainly threading.

PHP:
Pros: Most preferred language, widely used, fast development, big community, huge available resource pool.
Cons: Some reported security loopholes, Less trustworthy, Market image as cheap and dirty option for quick development, multi-threading issue, debugging issues.

Ruby:
Pros: Very flexible, good support, positive image in communities, Very popular framework for web development (ROR).
Cons: Some benchmarks shows that its request-response time is a bit slow than others in same category, Getting good resources can be difficult.

Again few things differ project to project so choose based on your own requirement.

I personally prefer Perl 5.

Switching from Perl to Python: Speed

A real time comparison. Long live Perl.

 

http://silicainsilico.wordpress.com/2012/03/26/switching-from-perl-to-python-speed/

 

Update:

Adding another comparison between various programming languages including Perl. This is bit old post but still relevant.

http://tenser.typepad.com/tenser_said_the_tensor/2006/08/python_vs_perl_.html

 

Don’t forget to read comments.