Skip to content

Instantly share code, notes, and snippets.

@sirex
Created May 24, 2016 15:07
Show Gist options
  • Save sirex/8cf10cca9e0ada6bd1bf805ced35e849 to your computer and use it in GitHub Desktop.
Save sirex/8cf10cca9e0ada6bd1bf805ced35e849 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import datapackage"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"cpi_dp = datapackage.push_datapackage('https://raw.githubusercontent.com/frictionlessdata/example-data-packages/master/cpi/datapackage.json', 'pandas')\n",
"gdp_dp = datapackage.push_datapackage('https://raw.githubusercontent.com/frictionlessdata/example-data-packages/master/gross-domestic-product-all/datapackage.json', 'pandas')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Country Name</th>\n",
" <th>Country Code</th>\n",
" <th>Year</th>\n",
" <th>CPI</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Afghanistan</td>\n",
" <td>AFG</td>\n",
" <td>2004-01-01</td>\n",
" <td>63.131893</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Afghanistan</td>\n",
" <td>AFG</td>\n",
" <td>2005-01-01</td>\n",
" <td>71.140974</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Afghanistan</td>\n",
" <td>AFG</td>\n",
" <td>2006-01-01</td>\n",
" <td>76.302178</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Afghanistan</td>\n",
" <td>AFG</td>\n",
" <td>2007-01-01</td>\n",
" <td>82.774807</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Afghanistan</td>\n",
" <td>AFG</td>\n",
" <td>2008-01-01</td>\n",
" <td>108.066600</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Country Name Country Code Year CPI\n",
"0 Afghanistan AFG 2004-01-01 63.131893\n",
"1 Afghanistan AFG 2005-01-01 71.140974\n",
"2 Afghanistan AFG 2006-01-01 76.302178\n",
"3 Afghanistan AFG 2007-01-01 82.774807\n",
"4 Afghanistan AFG 2008-01-01 108.066600"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cpi_dp['data__cpi'].head()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Country Name</th>\n",
" <th>Country Code</th>\n",
" <th>Year</th>\n",
" <th>Value</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Arab World</td>\n",
" <td>ARB</td>\n",
" <td>1968-01-01</td>\n",
" <td>2.565909e+10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Arab World</td>\n",
" <td>ARB</td>\n",
" <td>1969-01-01</td>\n",
" <td>2.830827e+10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Arab World</td>\n",
" <td>ARB</td>\n",
" <td>1970-01-01</td>\n",
" <td>3.122424e+10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Arab World</td>\n",
" <td>ARB</td>\n",
" <td>1971-01-01</td>\n",
" <td>3.622961e+10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Arab World</td>\n",
" <td>ARB</td>\n",
" <td>1972-01-01</td>\n",
" <td>4.313517e+10</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Country Name Country Code Year Value\n",
"0 Arab World ARB 1968-01-01 2.565909e+10\n",
"1 Arab World ARB 1969-01-01 2.830827e+10\n",
"2 Arab World ARB 1970-01-01 3.122424e+10\n",
"3 Arab World ARB 1971-01-01 3.622961e+10\n",
"4 Arab World ARB 1972-01-01 4.313517e+10"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gdp_dp['data__gdp___gdp'].head()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Country Name</th>\n",
" <th>Country Code</th>\n",
" <th>Year</th>\n",
" <th>CPI</th>\n",
" <th>Value</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Afghanistan</td>\n",
" <td>AFG</td>\n",
" <td>2004-01-01</td>\n",
" <td>63.131893</td>\n",
" <td>5.285462e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Afghanistan</td>\n",
" <td>AFG</td>\n",
" <td>2005-01-01</td>\n",
" <td>71.140974</td>\n",
" <td>6.275076e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Afghanistan</td>\n",
" <td>AFG</td>\n",
" <td>2006-01-01</td>\n",
" <td>76.302178</td>\n",
" <td>7.057598e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Afghanistan</td>\n",
" <td>AFG</td>\n",
" <td>2007-01-01</td>\n",
" <td>82.774807</td>\n",
" <td>9.843842e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Afghanistan</td>\n",
" <td>AFG</td>\n",
" <td>2008-01-01</td>\n",
" <td>108.066600</td>\n",
" <td>1.019053e+10</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Country Name Country Code Year CPI Value\n",
"0 Afghanistan AFG 2004-01-01 63.131893 5.285462e+09\n",
"1 Afghanistan AFG 2005-01-01 71.140974 6.275076e+09\n",
"2 Afghanistan AFG 2006-01-01 76.302178 7.057598e+09\n",
"3 Afghanistan AFG 2007-01-01 82.774807 9.843842e+09\n",
"4 Afghanistan AFG 2008-01-01 108.066600 1.019053e+10"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cpi_dp['data__cpi'].merge(gdp_dp['data__gdp___gdp'], on=['Country Name', 'Country Code', 'Year']).head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment