Skip to content

Instantly share code, notes, and snippets.

[
{
"page": "1",
"pages": "1",
"per_page": "50",
"total": "28"
},
[
{
"id": "11",
import wbdata
import pandas
import matplotlib.pyplot as plt
#set up the countries I want
countries = ["CL","UY","HU"]
#set up the indicator I want (just build up the dict if you want more than one)
indicators = {'NY.GNP.PCAP.CD':'GNI per Capita'}
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Country Name 2005 2006 2007 2008 2009
Afghanistan 46.6 46.9 47.2 47.5 47.9
Albania 76.1 76.3 76.5 76.6 76.8
Algeria 71.6 71.9 72.2 72.4 72.6
Country Year Life Expectancy
Afghanistan 2005 46.6
Afghanistan 2006 46.9
Afghanistan 2007 47.2
Afghanistan 2008 47.5
Afghanistan 2009 47.9
Albania 2005 76.1
Albania 2006 76.3
Albania 2007 76.5
Albania 2008 76.6
Afghanistan 2005 46.6
Afghanistan 2006 46.9
Afghanistan 2007 47.2
Afghanistan 2008 47.5
Afghanistan 2009 47.9
Albania 2005 76.1
Albania 2006 76.3
Albania 2007 76.5
Albania 2008 76.6
@tkb
tkb / unpivot-le.py
Last active December 20, 2015 13:09
import pandas as pd
#read the normalized CSV file
df = pandas.read_csv('lifeexpectancy.csv')
#melt the normalized file, hold the country name and code variables, rename the melted columns
le = pd.melt(df, id_vars=['Country Name','Country Code'], var_name="year", value_name="life_expectancy")
#sort by country name for convenience
le2 = le.sort(['Country Name'])
{
"metadata": {
"name": "unpivoting-csv-pandas"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@tkb
tkb / README.md
Created August 14, 2013 12:43
Life Table Survivors by Age

This interactive chart shows "survival curves" for females in different countries.

Calcualted from life tables, these survival curves show the expected number of survivors from birth to 85 at 5-year intervals from a hypothetical cohort of 100,000.

@tkb
tkb / README.md
Created August 14, 2013 16:55
Life Table Survivors by Age

This interactive chart shows "survival curves" for females in different countries.

Calcualted from life tables, these survival curves show the expected number of survivors from birth to 85 at 5-year intervals from a hypothetical cohort of 100,000.

@tkb
tkb / le.md
Last active December 21, 2015 22:49
Life Expectancy