Skip to content

Instantly share code, notes, and snippets.

@ianepreston
Created April 15, 2020 19:53
Show Gist options
  • Save ianepreston/37eaf10d15eeb560bb77dad18a9a323c to your computer and use it in GitHub Desktop.
Save ianepreston/37eaf10d15eeb560bb77dad18a9a323c 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": {},
"outputs": [],
"source": [
"from stats_can import StatsCan"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"sc = StatsCan()"
]
},
{
"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>Case information</th>\n",
" <th>Age group</th>\n",
" <th>Gender</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Case identifier number</th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>5</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1000</th>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10000</th>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
"Case information Age group Gender\n",
"Case identifier number \n",
"1 5 1\n",
"10 4 1\n",
"100 4 1\n",
"1000 1 1\n",
"10000 3 1"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = (\n",
" sc.table_to_df(\"13-10-0766-01\")\n",
" .loc[lambda df: df[\"Case information\"].isin(['Gender', 'Age group'])]\n",
" .reindex(columns=[\"Case identifier number\", \"Case information\", \"VALUE\"])\n",
" .set_index([\"Case identifier number\", \"Case information\"])\n",
" .unstack(level=1)\n",
" .droplevel(axis=\"columns\", level=0)\n",
" .astype(int)\n",
")\n",
"df.head()"
]
},
{
"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.8.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment