Newer
Older
DataReport / dataset-stats / size.ipynb
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Gather some statistics about the datasets, vocabularies and codelists loaded into PMD."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from SPARQLWrapper import SPARQLWrapper2\n",
    "import pandas as pd\n",
    "from IPython.display import HTML\n",
    "\n",
    "endpoint = \"https://production-drafter-ons-alpha.publishmydata.com/v1/sparql/live\"\n",
    "sparql = SPARQLWrapper2(endpoint)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Find the number of observations in each dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Observations</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/hmrc-regional-trade-statistics</th>\n",
       "      <td>3241972</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/hmrc-overseas-trade-statistics</th>\n",
       "      <td>1499970</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-cpa</th>\n",
       "      <td>399992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-trade-in-goods-mrets</th>\n",
       "      <td>264270</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-bop-individual-country-data</th>\n",
       "      <td>80756</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-pink-book-chapter-3</th>\n",
       "      <td>5378</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-age-and-sex</th>\n",
       "      <td>2819</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-abs</th>\n",
       "      <td>2025</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-citizenship</th>\n",
       "      <td>1706</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-country-of-residence</th>\n",
       "      <td>1472</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-uk-destination-or-origin</th>\n",
       "      <td>1208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-occupation</th>\n",
       "      <td>947</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/hmrc-uk-trade-in-goods-statistics-by-business-characteristics-2015</th>\n",
       "      <td>947</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-reason-for-migration</th>\n",
       "      <td>828</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-balance-of-payments</th>\n",
       "      <td>396</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   Observations\n",
       "http://gss-data.org.uk/data/hmrc-regional-trade...      3241972\n",
       "http://gss-data.org.uk/data/hmrc-overseas-trade...      1499970\n",
       "http://gss-data.org.uk/data/ons-cpa                      399992\n",
       "http://gss-data.org.uk/data/ons-trade-in-goods-...       264270\n",
       "http://gss-data.org.uk/data/ons-bop-individual-...        80756\n",
       "http://gss-data.org.uk/data/ons-pink-book-chapt...         5378\n",
       "http://gss-data.org.uk/data/ons-ltim-age-and-sex           2819\n",
       "http://gss-data.org.uk/data/ons-abs                        2025\n",
       "http://gss-data.org.uk/data/ons-ltim-citizenship           1706\n",
       "http://gss-data.org.uk/data/ons-ltim-country-of...         1472\n",
       "http://gss-data.org.uk/data/ons-ltim-uk-destina...         1208\n",
       "http://gss-data.org.uk/data/ons-ltim-occupation             947\n",
       "http://gss-data.org.uk/data/hmrc-uk-trade-in-go...          947\n",
       "http://gss-data.org.uk/data/ons-ltim-reason-for...          828\n",
       "http://gss-data.org.uk/data/ons-balance-of-paym...          396"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sparql.setQuery(\"\"\"\n",
    "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
    "PREFIX qb:   <http://purl.org/linked-data/cube#>\n",
    "\n",
    "SELECT (COUNT(?obs) AS ?observations) ?dataset\n",
    "WHERE {\n",
    "  ?obs a qb:Observation ;\n",
    "         qb:dataSet ?dataset .\n",
    "} GROUP BY ?dataset ORDER BY DESC(?observations)\n",
    "\"\"\")\n",
    "\n",
    "table = pd.DataFrame()\n",
    "table['Observations'] = pd.Series({\n",
    "    res['dataset'].value : res['observations'].value\n",
    "    for res in sparql.query().bindings\n",
    "})\n",
    "table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Observations</th>\n",
       "      <th>Label</th>\n",
       "      <th>Graph</th>\n",
       "      <th>Family</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/hmrc-regional-trade-statistics</th>\n",
       "      <td>3241972</td>\n",
       "      <td>HMRC Regional Trade Statistics</td>\n",
       "      <td>http://gss-data.org.uk/graph/hmrc-regional-tra...</td>\n",
       "      <td>Trade</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/hmrc-overseas-trade-statistics</th>\n",
       "      <td>1499970</td>\n",
       "      <td>HMRC Overseas Trade Statistics</td>\n",
       "      <td>http://gss-data.org.uk/graph/hmrc-overseas-tra...</td>\n",
       "      <td>Trade</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-cpa</th>\n",
       "      <td>399992</td>\n",
       "      <td>ONS CPA</td>\n",
       "      <td>http://gss-data.org.uk/graph/ons-cpa</td>\n",
       "      <td>Trade</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-trade-in-goods-mrets</th>\n",
       "      <td>264270</td>\n",
       "      <td>ONS Trade in goods MRETS</td>\n",
       "      <td>http://gss-data.org.uk/graph/ons-trade-in-good...</td>\n",
       "      <td>Trade</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-bop-individual-country-data</th>\n",
       "      <td>80756</td>\n",
       "      <td>ONS BoP Individual Country Data</td>\n",
       "      <td>http://gss-data.org.uk/graph/ons-bop-individua...</td>\n",
       "      <td>Trade</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-pink-book-chapter-3</th>\n",
       "      <td>5378</td>\n",
       "      <td>ONS Pink Book Chapter 3</td>\n",
       "      <td>http://gss-data.org.uk/graph/ons-pink-book-cha...</td>\n",
       "      <td>Trade</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-age-and-sex</th>\n",
       "      <td>2819</td>\n",
       "      <td>ONS LTIM Age and Sex</td>\n",
       "      <td>http://gss-data.org.uk/graph/ons-ltim-age-and-sex</td>\n",
       "      <td>Migration</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-abs</th>\n",
       "      <td>2025</td>\n",
       "      <td>ONS ABS</td>\n",
       "      <td>http://gss-data.org.uk/graph/ons-abs</td>\n",
       "      <td>Trade</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-citizenship</th>\n",
       "      <td>1706</td>\n",
       "      <td>ONS LTIM citizenship</td>\n",
       "      <td>http://gss-data.org.uk/graph/ons-ltim-citizenship</td>\n",
       "      <td>Migration</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-country-of-residence</th>\n",
       "      <td>1472</td>\n",
       "      <td>ONS LTIM country of residence</td>\n",
       "      <td>http://gss-data.org.uk/graph/ons-ltim-country-...</td>\n",
       "      <td>Migration</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-uk-destination-or-origin</th>\n",
       "      <td>1208</td>\n",
       "      <td>ONS LTIM UK Destination or Origin</td>\n",
       "      <td>http://gss-data.org.uk/graph/ons-ltim-uk-desti...</td>\n",
       "      <td>Migration</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-occupation</th>\n",
       "      <td>947</td>\n",
       "      <td>ONS LTIM Occupation</td>\n",
       "      <td>http://gss-data.org.uk/graph/ons-ltim-occupation</td>\n",
       "      <td>Migration</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/hmrc-uk-trade-in-goods-statistics-by-business-characteristics-2015</th>\n",
       "      <td>947</td>\n",
       "      <td>HMRC UK Trade in Goods Statistics by Business ...</td>\n",
       "      <td>http://gss-data.org.uk/graph/hmrc-uk-trade-in-...</td>\n",
       "      <td>Trade</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-reason-for-migration</th>\n",
       "      <td>828</td>\n",
       "      <td>Long-term international migration 2.06, area o...</td>\n",
       "      <td>http://gss-data.org.uk/graph/ons-ltim-reason-f...</td>\n",
       "      <td>Migration</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-balance-of-payments</th>\n",
       "      <td>396</td>\n",
       "      <td>ONS Balance of Payments</td>\n",
       "      <td>http://gss-data.org.uk/graph/ons-balance-of-pa...</td>\n",
       "      <td>Trade</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   Observations  \\\n",
       "http://gss-data.org.uk/data/hmrc-regional-trade...      3241972   \n",
       "http://gss-data.org.uk/data/hmrc-overseas-trade...      1499970   \n",
       "http://gss-data.org.uk/data/ons-cpa                      399992   \n",
       "http://gss-data.org.uk/data/ons-trade-in-goods-...       264270   \n",
       "http://gss-data.org.uk/data/ons-bop-individual-...        80756   \n",
       "http://gss-data.org.uk/data/ons-pink-book-chapt...         5378   \n",
       "http://gss-data.org.uk/data/ons-ltim-age-and-sex           2819   \n",
       "http://gss-data.org.uk/data/ons-abs                        2025   \n",
       "http://gss-data.org.uk/data/ons-ltim-citizenship           1706   \n",
       "http://gss-data.org.uk/data/ons-ltim-country-of...         1472   \n",
       "http://gss-data.org.uk/data/ons-ltim-uk-destina...         1208   \n",
       "http://gss-data.org.uk/data/ons-ltim-occupation             947   \n",
       "http://gss-data.org.uk/data/hmrc-uk-trade-in-go...          947   \n",
       "http://gss-data.org.uk/data/ons-ltim-reason-for...          828   \n",
       "http://gss-data.org.uk/data/ons-balance-of-paym...          396   \n",
       "\n",
       "                                                                                                Label  \\\n",
       "http://gss-data.org.uk/data/hmrc-regional-trade...                     HMRC Regional Trade Statistics   \n",
       "http://gss-data.org.uk/data/hmrc-overseas-trade...                     HMRC Overseas Trade Statistics   \n",
       "http://gss-data.org.uk/data/ons-cpa                                                           ONS CPA   \n",
       "http://gss-data.org.uk/data/ons-trade-in-goods-...                           ONS Trade in goods MRETS   \n",
       "http://gss-data.org.uk/data/ons-bop-individual-...                    ONS BoP Individual Country Data   \n",
       "http://gss-data.org.uk/data/ons-pink-book-chapt...                            ONS Pink Book Chapter 3   \n",
       "http://gss-data.org.uk/data/ons-ltim-age-and-sex                                 ONS LTIM Age and Sex   \n",
       "http://gss-data.org.uk/data/ons-abs                                                           ONS ABS   \n",
       "http://gss-data.org.uk/data/ons-ltim-citizenship                                 ONS LTIM citizenship   \n",
       "http://gss-data.org.uk/data/ons-ltim-country-of...                      ONS LTIM country of residence   \n",
       "http://gss-data.org.uk/data/ons-ltim-uk-destina...                  ONS LTIM UK Destination or Origin   \n",
       "http://gss-data.org.uk/data/ons-ltim-occupation                                   ONS LTIM Occupation   \n",
       "http://gss-data.org.uk/data/hmrc-uk-trade-in-go...  HMRC UK Trade in Goods Statistics by Business ...   \n",
       "http://gss-data.org.uk/data/ons-ltim-reason-for...  Long-term international migration 2.06, area o...   \n",
       "http://gss-data.org.uk/data/ons-balance-of-paym...                            ONS Balance of Payments   \n",
       "\n",
       "                                                                                                Graph  \\\n",
       "http://gss-data.org.uk/data/hmrc-regional-trade...  http://gss-data.org.uk/graph/hmrc-regional-tra...   \n",
       "http://gss-data.org.uk/data/hmrc-overseas-trade...  http://gss-data.org.uk/graph/hmrc-overseas-tra...   \n",
       "http://gss-data.org.uk/data/ons-cpa                              http://gss-data.org.uk/graph/ons-cpa   \n",
       "http://gss-data.org.uk/data/ons-trade-in-goods-...  http://gss-data.org.uk/graph/ons-trade-in-good...   \n",
       "http://gss-data.org.uk/data/ons-bop-individual-...  http://gss-data.org.uk/graph/ons-bop-individua...   \n",
       "http://gss-data.org.uk/data/ons-pink-book-chapt...  http://gss-data.org.uk/graph/ons-pink-book-cha...   \n",
       "http://gss-data.org.uk/data/ons-ltim-age-and-sex    http://gss-data.org.uk/graph/ons-ltim-age-and-sex   \n",
       "http://gss-data.org.uk/data/ons-abs                              http://gss-data.org.uk/graph/ons-abs   \n",
       "http://gss-data.org.uk/data/ons-ltim-citizenship    http://gss-data.org.uk/graph/ons-ltim-citizenship   \n",
       "http://gss-data.org.uk/data/ons-ltim-country-of...  http://gss-data.org.uk/graph/ons-ltim-country-...   \n",
       "http://gss-data.org.uk/data/ons-ltim-uk-destina...  http://gss-data.org.uk/graph/ons-ltim-uk-desti...   \n",
       "http://gss-data.org.uk/data/ons-ltim-occupation      http://gss-data.org.uk/graph/ons-ltim-occupation   \n",
       "http://gss-data.org.uk/data/hmrc-uk-trade-in-go...  http://gss-data.org.uk/graph/hmrc-uk-trade-in-...   \n",
       "http://gss-data.org.uk/data/ons-ltim-reason-for...  http://gss-data.org.uk/graph/ons-ltim-reason-f...   \n",
       "http://gss-data.org.uk/data/ons-balance-of-paym...  http://gss-data.org.uk/graph/ons-balance-of-pa...   \n",
       "\n",
       "                                                       Family  \n",
       "http://gss-data.org.uk/data/hmrc-regional-trade...      Trade  \n",
       "http://gss-data.org.uk/data/hmrc-overseas-trade...      Trade  \n",
       "http://gss-data.org.uk/data/ons-cpa                     Trade  \n",
       "http://gss-data.org.uk/data/ons-trade-in-goods-...      Trade  \n",
       "http://gss-data.org.uk/data/ons-bop-individual-...      Trade  \n",
       "http://gss-data.org.uk/data/ons-pink-book-chapt...      Trade  \n",
       "http://gss-data.org.uk/data/ons-ltim-age-and-sex    Migration  \n",
       "http://gss-data.org.uk/data/ons-abs                     Trade  \n",
       "http://gss-data.org.uk/data/ons-ltim-citizenship    Migration  \n",
       "http://gss-data.org.uk/data/ons-ltim-country-of...  Migration  \n",
       "http://gss-data.org.uk/data/ons-ltim-uk-destina...  Migration  \n",
       "http://gss-data.org.uk/data/ons-ltim-occupation     Migration  \n",
       "http://gss-data.org.uk/data/hmrc-uk-trade-in-go...      Trade  \n",
       "http://gss-data.org.uk/data/ons-ltim-reason-for...  Migration  \n",
       "http://gss-data.org.uk/data/ons-balance-of-paym...      Trade  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sparql.setQuery(\"\"\"\n",
    "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
    "PREFIX qb:   <http://purl.org/linked-data/cube#>\n",
    "PREFIX pmd:  <http://publishmydata.com/def/dataset#>\n",
    "PREFIX gdp:  <http://gss-data.org.uk/def/gdp#>\n",
    "\n",
    "SELECT DISTINCT ?dataset ?datasetLabel ?graph ?family\n",
    "WHERE {\n",
    "  ?dataset a qb:DataSet ;\n",
    "         rdfs:label ?datasetLabel ;\n",
    "         pmd:graph ?graph .\n",
    "  OPTIONAL {\n",
    "    ?dataset gdp:family [rdfs:label ?family]\n",
    "  }\n",
    "}\n",
    "\"\"\")\n",
    "\n",
    "results = sparql.query().bindings\n",
    "\n",
    "table['Label'] = pd.Series({\n",
    "    res['dataset'].value: res['datasetLabel'].value\n",
    "    for res in results\n",
    "})\n",
    "\n",
    "table['Graph'] = pd.Series({\n",
    "    res['dataset'].value: res['graph'].value\n",
    "    for res in results\n",
    "})\n",
    "\n",
    "table['Family'] = pd.Series({\n",
    "    res['dataset'].value: res['family'].value if 'family' in res else 'Trade'\n",
    "    for res in results\n",
    "})\n",
    "table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Triples</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>http://purl.org/dc/terms/</th>\n",
       "      <td>866</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/cpav2008-cpav21</th>\n",
       "      <td>28071</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/cpav2008</th>\n",
       "      <td>47707</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/cpav21</th>\n",
       "      <td>44275</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/cpcv11</th>\n",
       "      <td>29269</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/cpcv2</th>\n",
       "      <td>44159</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/cpcv21</th>\n",
       "      <td>36837</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/cpcv11-cpcv2</th>\n",
       "      <td>15202</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/cpcv2-cpcv21</th>\n",
       "      <td>14788</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/isicr31</th>\n",
       "      <td>5438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/isicr31-cpcv11</th>\n",
       "      <td>13350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/isicr31-isicr4</th>\n",
       "      <td>4116</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/isicr4</th>\n",
       "      <td>9249</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/isicr4-cpcv21</th>\n",
       "      <td>13320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/isicr4-cpcv2</th>\n",
       "      <td>12305</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/isicr4-nacer2</th>\n",
       "      <td>4311</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/isicr4-naics2012</th>\n",
       "      <td>7591</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/nacer11</th>\n",
       "      <td>9605</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/nacer2</th>\n",
       "      <td>12806</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/nacer2-cpav21</th>\n",
       "      <td>16066</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/nacer2-cpav2008</th>\n",
       "      <td>15716</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/nacer11-nacer2</th>\n",
       "      <td>5096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/semstats/naics2012</th>\n",
       "      <td>17756</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://xmlns.com/foaf/0.1/</th>\n",
       "      <td>631</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://publishmydata.com/graph/vocabulary/22-rdf-syntax-ns</th>\n",
       "      <td>102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://publishmydata.com/graph/vocabulary/admingeo</th>\n",
       "      <td>1801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://publishmydata.com/graph/vocabulary/sdmx</th>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://publishmydata.com/graph/vocabulary/skos</th>\n",
       "      <td>259</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://publishmydata.com/graph/vocabulary/sdmx-subject</th>\n",
       "      <td>295</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://publishmydata.com/graph/vocabulary/statistical-quality</th>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>https://trade.ec.europa.eu/def/cn_2016</th>\n",
       "      <td>61369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/ons-abs-trades</th>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/ons-ltim-citizenship/metadata</th>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/ons-ltim-reason-for-migration/metadata</th>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/ons-ltim-occupation/metadata</th>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://www.ons.gov.uk/dev/sic2007</th>\n",
       "      <td>5995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/citizenship</th>\n",
       "      <td>272</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/ons-ltim-citizenship</th>\n",
       "      <td>48123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/ons-ltim-reason-for-migration</th>\n",
       "      <td>21838</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/ons-ltim-occupation</th>\n",
       "      <td>26865</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://rdf-vocabulary.ddialliance.org/xkos</th>\n",
       "      <td>322</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/def/gdp</th>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://purl.org/dc/elements/1.1</th>\n",
       "      <td>138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>https://creativecommons.org/schema.rdf</th>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://www.w3.org/ns/ui</th>\n",
       "      <td>523</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://purl.org/vocommons/voaf</th>\n",
       "      <td>321</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://www.w3.org/2003/06/sw-vocab-status/ns</th>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/citizenships</th>\n",
       "      <td>3293</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/migration-directions</th>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/ons-ltim-country-of-residence</th>\n",
       "      <td>67894</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/ons-ltim-country-of-residence/metadata</th>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/reasons-for-migration</th>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/occupations</th>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/country-of-residence</th>\n",
       "      <td>328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/revisions</th>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/ons-ltim-uk-destination-or-origin</th>\n",
       "      <td>34185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/ons-ltim-age-and-sex/metadata</th>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/ons-ltim-age-and-sex</th>\n",
       "      <td>84949</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/ages</th>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/graph/ons-ltim-uk-destination-or-origin/metadata</th>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>131 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                    Triples\n",
       "http://purl.org/dc/terms/                               866\n",
       "http://gss-data.org.uk/graph/semstats/cpav2008-...    28071\n",
       "http://gss-data.org.uk/graph/semstats/cpav2008        47707\n",
       "http://gss-data.org.uk/graph/semstats/cpav21          44275\n",
       "http://gss-data.org.uk/graph/semstats/cpcv11          29269\n",
       "http://gss-data.org.uk/graph/semstats/cpcv2           44159\n",
       "http://gss-data.org.uk/graph/semstats/cpcv21          36837\n",
       "http://gss-data.org.uk/graph/semstats/cpcv11-cpcv2    15202\n",
       "http://gss-data.org.uk/graph/semstats/cpcv2-cpcv21    14788\n",
       "http://gss-data.org.uk/graph/semstats/isicr31          5438\n",
       "http://gss-data.org.uk/graph/semstats/isicr31-c...    13350\n",
       "http://gss-data.org.uk/graph/semstats/isicr31-i...     4116\n",
       "http://gss-data.org.uk/graph/semstats/isicr4           9249\n",
       "http://gss-data.org.uk/graph/semstats/isicr4-cp...    13320\n",
       "http://gss-data.org.uk/graph/semstats/isicr4-cpcv2    12305\n",
       "http://gss-data.org.uk/graph/semstats/isicr4-na...     4311\n",
       "http://gss-data.org.uk/graph/semstats/isicr4-na...     7591\n",
       "http://gss-data.org.uk/graph/semstats/nacer11          9605\n",
       "http://gss-data.org.uk/graph/semstats/nacer2          12806\n",
       "http://gss-data.org.uk/graph/semstats/nacer2-cp...    16066\n",
       "http://gss-data.org.uk/graph/semstats/nacer2-cp...    15716\n",
       "http://gss-data.org.uk/graph/semstats/nacer11-n...     5096\n",
       "http://gss-data.org.uk/graph/semstats/naics2012       17756\n",
       "http://xmlns.com/foaf/0.1/                              631\n",
       "http://publishmydata.com/graph/vocabulary/22-rd...      102\n",
       "http://publishmydata.com/graph/vocabulary/admingeo     1801\n",
       "http://publishmydata.com/graph/vocabulary/sdmx          100\n",
       "http://publishmydata.com/graph/vocabulary/skos          259\n",
       "http://publishmydata.com/graph/vocabulary/sdmx-...      295\n",
       "http://publishmydata.com/graph/vocabulary/stati...       32\n",
       "...                                                     ...\n",
       "https://trade.ec.europa.eu/def/cn_2016                61369\n",
       "http://gss-data.org.uk/graph/ons-abs-trades              41\n",
       "http://gss-data.org.uk/graph/ons-ltim-citizensh...       15\n",
       "http://gss-data.org.uk/graph/ons-ltim-reason-fo...       20\n",
       "http://gss-data.org.uk/graph/ons-ltim-occupatio...       15\n",
       "http://www.ons.gov.uk/dev/sic2007                      5995\n",
       "http://gss-data.org.uk/graph/citizenship                272\n",
       "http://gss-data.org.uk/graph/ons-ltim-citizenship     48123\n",
       "http://gss-data.org.uk/graph/ons-ltim-reason-fo...    21838\n",
       "http://gss-data.org.uk/graph/ons-ltim-occupation      26865\n",
       "http://rdf-vocabulary.ddialliance.org/xkos              322\n",
       "http://gss-data.org.uk/def/gdp                           28\n",
       "http://purl.org/dc/elements/1.1                         138\n",
       "https://creativecommons.org/schema.rdf                  115\n",
       "http://www.w3.org/ns/ui                                 523\n",
       "http://purl.org/vocommons/voaf                          321\n",
       "http://www.w3.org/2003/06/sw-vocab-status/ns             27\n",
       "http://gss-data.org.uk/graph/citizenships              3293\n",
       "http://gss-data.org.uk/graph/migration-directions        43\n",
       "http://gss-data.org.uk/graph/ons-ltim-country-o...    67894\n",
       "http://gss-data.org.uk/graph/ons-ltim-country-o...       15\n",
       "http://gss-data.org.uk/graph/reasons-for-migration      104\n",
       "http://gss-data.org.uk/graph/occupations                 74\n",
       "http://gss-data.org.uk/graph/country-of-residence       328\n",
       "http://gss-data.org.uk/graph/revisions                   31\n",
       "http://gss-data.org.uk/graph/ons-ltim-uk-destin...    34185\n",
       "http://gss-data.org.uk/graph/ons-ltim-age-and-s...       16\n",
       "http://gss-data.org.uk/graph/ons-ltim-age-and-sex     84949\n",
       "http://gss-data.org.uk/graph/ages                        74\n",
       "http://gss-data.org.uk/graph/ons-ltim-uk-destin...       16\n",
       "\n",
       "[131 rows x 1 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sparql.setQuery(\"\"\"\n",
    "SELECT (COUNT(*) as ?size) ?graph\n",
    "WHERE {\n",
    "  GRAPH ?graph {\n",
    "    ?s ?p ?o\n",
    "  }\n",
    "} GROUP BY ?graph\n",
    "\"\"\")\n",
    "\n",
    "sizes = pd.DataFrame()\n",
    "sizes['Triples'] = pd.Series({\n",
    "    res['graph'].value : int(res['size'].value)\n",
    "    for res in sparql.query().bindings\n",
    "})\n",
    "sizes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Observations</th>\n",
       "      <th>Label</th>\n",
       "      <th>Family</th>\n",
       "      <th>Triples</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/hmrc-regional-trade-statistics</th>\n",
       "      <td>3241972</td>\n",
       "      <td>HMRC Regional Trade Statistics</td>\n",
       "      <td>Trade</td>\n",
       "      <td>84297394</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/hmrc-overseas-trade-statistics</th>\n",
       "      <td>1499970</td>\n",
       "      <td>HMRC Overseas Trade Statistics</td>\n",
       "      <td>Trade</td>\n",
       "      <td>36048123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-cpa</th>\n",
       "      <td>399992</td>\n",
       "      <td>ONS CPA</td>\n",
       "      <td>Trade</td>\n",
       "      <td>12806153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-trade-in-goods-mrets</th>\n",
       "      <td>264270</td>\n",
       "      <td>ONS Trade in goods MRETS</td>\n",
       "      <td>Trade</td>\n",
       "      <td>7929621</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-bop-individual-country-data</th>\n",
       "      <td>80756</td>\n",
       "      <td>ONS BoP Individual Country Data</td>\n",
       "      <td>Trade</td>\n",
       "      <td>1777303</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-pink-book-chapter-3</th>\n",
       "      <td>5378</td>\n",
       "      <td>ONS Pink Book Chapter 3</td>\n",
       "      <td>Trade</td>\n",
       "      <td>150770</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-age-and-sex</th>\n",
       "      <td>2819</td>\n",
       "      <td>ONS LTIM Age and Sex</td>\n",
       "      <td>Migration</td>\n",
       "      <td>84949</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-abs</th>\n",
       "      <td>2025</td>\n",
       "      <td>ONS ABS</td>\n",
       "      <td>Trade</td>\n",
       "      <td>61101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-citizenship</th>\n",
       "      <td>1706</td>\n",
       "      <td>ONS LTIM citizenship</td>\n",
       "      <td>Migration</td>\n",
       "      <td>48123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-country-of-residence</th>\n",
       "      <td>1472</td>\n",
       "      <td>ONS LTIM country of residence</td>\n",
       "      <td>Migration</td>\n",
       "      <td>67894</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-uk-destination-or-origin</th>\n",
       "      <td>1208</td>\n",
       "      <td>ONS LTIM UK Destination or Origin</td>\n",
       "      <td>Migration</td>\n",
       "      <td>34185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-occupation</th>\n",
       "      <td>947</td>\n",
       "      <td>ONS LTIM Occupation</td>\n",
       "      <td>Migration</td>\n",
       "      <td>26865</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/hmrc-uk-trade-in-goods-statistics-by-business-characteristics-2015</th>\n",
       "      <td>947</td>\n",
       "      <td>HMRC UK Trade in Goods Statistics by Business ...</td>\n",
       "      <td>Trade</td>\n",
       "      <td>27243</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-ltim-reason-for-migration</th>\n",
       "      <td>828</td>\n",
       "      <td>Long-term international migration 2.06, area o...</td>\n",
       "      <td>Migration</td>\n",
       "      <td>21838</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>http://gss-data.org.uk/data/ons-balance-of-payments</th>\n",
       "      <td>396</td>\n",
       "      <td>ONS Balance of Payments</td>\n",
       "      <td>Trade</td>\n",
       "      <td>10593</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   Observations  \\\n",
       "http://gss-data.org.uk/data/hmrc-regional-trade...      3241972   \n",
       "http://gss-data.org.uk/data/hmrc-overseas-trade...      1499970   \n",
       "http://gss-data.org.uk/data/ons-cpa                      399992   \n",
       "http://gss-data.org.uk/data/ons-trade-in-goods-...       264270   \n",
       "http://gss-data.org.uk/data/ons-bop-individual-...        80756   \n",
       "http://gss-data.org.uk/data/ons-pink-book-chapt...         5378   \n",
       "http://gss-data.org.uk/data/ons-ltim-age-and-sex           2819   \n",
       "http://gss-data.org.uk/data/ons-abs                        2025   \n",
       "http://gss-data.org.uk/data/ons-ltim-citizenship           1706   \n",
       "http://gss-data.org.uk/data/ons-ltim-country-of...         1472   \n",
       "http://gss-data.org.uk/data/ons-ltim-uk-destina...         1208   \n",
       "http://gss-data.org.uk/data/ons-ltim-occupation             947   \n",
       "http://gss-data.org.uk/data/hmrc-uk-trade-in-go...          947   \n",
       "http://gss-data.org.uk/data/ons-ltim-reason-for...          828   \n",
       "http://gss-data.org.uk/data/ons-balance-of-paym...          396   \n",
       "\n",
       "                                                                                                Label  \\\n",
       "http://gss-data.org.uk/data/hmrc-regional-trade...                     HMRC Regional Trade Statistics   \n",
       "http://gss-data.org.uk/data/hmrc-overseas-trade...                     HMRC Overseas Trade Statistics   \n",
       "http://gss-data.org.uk/data/ons-cpa                                                           ONS CPA   \n",
       "http://gss-data.org.uk/data/ons-trade-in-goods-...                           ONS Trade in goods MRETS   \n",
       "http://gss-data.org.uk/data/ons-bop-individual-...                    ONS BoP Individual Country Data   \n",
       "http://gss-data.org.uk/data/ons-pink-book-chapt...                            ONS Pink Book Chapter 3   \n",
       "http://gss-data.org.uk/data/ons-ltim-age-and-sex                                 ONS LTIM Age and Sex   \n",
       "http://gss-data.org.uk/data/ons-abs                                                           ONS ABS   \n",
       "http://gss-data.org.uk/data/ons-ltim-citizenship                                 ONS LTIM citizenship   \n",
       "http://gss-data.org.uk/data/ons-ltim-country-of...                      ONS LTIM country of residence   \n",
       "http://gss-data.org.uk/data/ons-ltim-uk-destina...                  ONS LTIM UK Destination or Origin   \n",
       "http://gss-data.org.uk/data/ons-ltim-occupation                                   ONS LTIM Occupation   \n",
       "http://gss-data.org.uk/data/hmrc-uk-trade-in-go...  HMRC UK Trade in Goods Statistics by Business ...   \n",
       "http://gss-data.org.uk/data/ons-ltim-reason-for...  Long-term international migration 2.06, area o...   \n",
       "http://gss-data.org.uk/data/ons-balance-of-paym...                            ONS Balance of Payments   \n",
       "\n",
       "                                                       Family   Triples  \n",
       "http://gss-data.org.uk/data/hmrc-regional-trade...      Trade  84297394  \n",
       "http://gss-data.org.uk/data/hmrc-overseas-trade...      Trade  36048123  \n",
       "http://gss-data.org.uk/data/ons-cpa                     Trade  12806153  \n",
       "http://gss-data.org.uk/data/ons-trade-in-goods-...      Trade   7929621  \n",
       "http://gss-data.org.uk/data/ons-bop-individual-...      Trade   1777303  \n",
       "http://gss-data.org.uk/data/ons-pink-book-chapt...      Trade    150770  \n",
       "http://gss-data.org.uk/data/ons-ltim-age-and-sex    Migration     84949  \n",
       "http://gss-data.org.uk/data/ons-abs                     Trade     61101  \n",
       "http://gss-data.org.uk/data/ons-ltim-citizenship    Migration     48123  \n",
       "http://gss-data.org.uk/data/ons-ltim-country-of...  Migration     67894  \n",
       "http://gss-data.org.uk/data/ons-ltim-uk-destina...  Migration     34185  \n",
       "http://gss-data.org.uk/data/ons-ltim-occupation     Migration     26865  \n",
       "http://gss-data.org.uk/data/hmrc-uk-trade-in-go...      Trade     27243  \n",
       "http://gss-data.org.uk/data/ons-ltim-reason-for...  Migration     21838  \n",
       "http://gss-data.org.uk/data/ons-balance-of-paym...      Trade     10593  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table = table.merge(sizes, left_on='Graph', right_index=True)\n",
    "table.drop(columns=['Graph'], inplace=True)\n",
    "table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>Dataset</th>\n",
       "      <th>Observations</th>\n",
       "      <th>Family</th>\n",
       "      <th>Triples</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td><a href=\"http://gss-data.org.uk/resource?uri=http%3A%2F%2Fgss-data.org.uk%2Fdata%2Fhmrc-regional-trade-statistics\">HMRC Regional Trade Statistics</a></td>\n",
       "      <td>3241972</td>\n",
       "      <td>Trade</td>\n",
       "      <td>84297394</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td><a href=\"http://gss-data.org.uk/resource?uri=http%3A%2F%2Fgss-data.org.uk%2Fdata%2Fhmrc-overseas-trade-statistics\">HMRC Overseas Trade Statistics</a></td>\n",
       "      <td>1499970</td>\n",
       "      <td>Trade</td>\n",
       "      <td>36048123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td><a href=\"http://gss-data.org.uk/resource?uri=http%3A%2F%2Fgss-data.org.uk%2Fdata%2Fons-cpa\">ONS CPA</a></td>\n",
       "      <td>399992</td>\n",
       "      <td>Trade</td>\n",
       "      <td>12806153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td><a href=\"http://gss-data.org.uk/resource?uri=http%3A%2F%2Fgss-data.org.uk%2Fdata%2Fons-trade-in-goods-mrets\">ONS Trade in goods MRETS</a></td>\n",
       "      <td>264270</td>\n",
       "      <td>Trade</td>\n",
       "      <td>7929621</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td><a href=\"http://gss-data.org.uk/resource?uri=http%3A%2F%2Fgss-data.org.uk%2Fdata%2Fons-bop-individual-country-data\">ONS BoP Individual Country Data</a></td>\n",
       "      <td>80756</td>\n",
       "      <td>Trade</td>\n",
       "      <td>1777303</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td><a href=\"http://gss-data.org.uk/resource?uri=http%3A%2F%2Fgss-data.org.uk%2Fdata%2Fons-pink-book-chapter-3\">ONS Pink Book Chapter 3</a></td>\n",
       "      <td>5378</td>\n",
       "      <td>Trade</td>\n",
       "      <td>150770</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td><a href=\"http://gss-data.org.uk/resource?uri=http%3A%2F%2Fgss-data.org.uk%2Fdata%2Fons-ltim-age-and-sex\">ONS LTIM Age and Sex</a></td>\n",
       "      <td>2819</td>\n",
       "      <td>Migration</td>\n",
       "      <td>84949</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td><a href=\"http://gss-data.org.uk/resource?uri=http%3A%2F%2Fgss-data.org.uk%2Fdata%2Fons-abs\">ONS ABS</a></td>\n",
       "      <td>2025</td>\n",
       "      <td>Trade</td>\n",
       "      <td>61101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td><a href=\"http://gss-data.org.uk/resource?uri=http%3A%2F%2Fgss-data.org.uk%2Fdata%2Fons-ltim-citizenship\">ONS LTIM citizenship</a></td>\n",
       "      <td>1706</td>\n",
       "      <td>Migration</td>\n",
       "      <td>48123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td><a href=\"http://gss-data.org.uk/resource?uri=http%3A%2F%2Fgss-data.org.uk%2Fdata%2Fons-ltim-country-of-residence\">ONS LTIM country of residence</a></td>\n",
       "      <td>1472</td>\n",
       "      <td>Migration</td>\n",
       "      <td>67894</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td><a href=\"http://gss-data.org.uk/resource?uri=http%3A%2F%2Fgss-data.org.uk%2Fdata%2Fons-ltim-uk-destination-or-origin\">ONS LTIM UK Destination or Origin</a></td>\n",
       "      <td>1208</td>\n",
       "      <td>Migration</td>\n",
       "      <td>34185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td><a href=\"http://gss-data.org.uk/resource?uri=http%3A%2F%2Fgss-data.org.uk%2Fdata%2Fons-ltim-occupation\">ONS LTIM Occupation</a></td>\n",
       "      <td>947</td>\n",
       "      <td>Migration</td>\n",
       "      <td>26865</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td><a href=\"http://gss-data.org.uk/resource?uri=http%3A%2F%2Fgss-data.org.uk%2Fdata%2Fhmrc-uk-trade-in-goods-statistics-by-business-characteristics-2015\">HMRC UK Trade in Goods Statistics by Business Characteristics 2015</a></td>\n",
       "      <td>947</td>\n",
       "      <td>Trade</td>\n",
       "      <td>27243</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td><a href=\"http://gss-data.org.uk/resource?uri=http%3A%2F%2Fgss-data.org.uk%2Fdata%2Fons-ltim-reason-for-migration\">Long-term international migration 2.06, area of destination or origin within the UK</a></td>\n",
       "      <td>828</td>\n",
       "      <td>Migration</td>\n",
       "      <td>21838</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td><a href=\"http://gss-data.org.uk/resource?uri=http%3A%2F%2Fgss-data.org.uk%2Fdata%2Fons-balance-of-payments\">ONS Balance of Payments</a></td>\n",
       "      <td>396</td>\n",
       "      <td>Trade</td>\n",
       "      <td>10593</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from urllib.parse import urlencode\n",
    "def gss_url(uri):\n",
    "    return 'http://gss-data.org.uk/resource?' + urlencode({\n",
    "        'uri': uri\n",
    "    })\n",
    "\n",
    "table['Dataset'] = table.apply(lambda x: f'<a href=\"{gss_url(x.name)}\">{x.Label}</a>', axis=1)\n",
    "table.drop(columns=['Label'], inplace=True)\n",
    "table = table[['Dataset', 'Observations', 'Family', 'Triples']]\n",
    "pd.set_option('max_colwidth', -1)\n",
    "with open('dataset-stats.html', 'w') as f:\n",
    "    f.write(table.to_html(escape=False, index=False))\n",
    "HTML(table.to_html(escape=False, index=False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "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.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}