Skip to content

Instantly share code, notes, and snippets.

@Antoninj
Last active August 19, 2019 21:27
Show Gist options
  • Save Antoninj/e5602de39167b0ca17ff687bf39ff61b to your computer and use it in GitHub Desktop.
Save Antoninj/e5602de39167b0ca17ff687bf39ff61b 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": {
"ExecuteTime": {
"end_time": "2019-08-19T21:25:59.448267Z",
"start_time": "2019-08-19T21:25:55.130262Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <script type=\"text/javascript\">\n",
" window.PlotlyConfig = {MathJaxConfig: 'local'};\n",
" if (window.MathJax) {MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}\n",
" if (typeof require !== 'undefined') {\n",
" require.undef(\"plotly\");\n",
" requirejs.config({\n",
" paths: {\n",
" 'plotly': ['https://cdn.plot.ly/plotly-latest.min']\n",
" }\n",
" });\n",
" require(['plotly'], function(Plotly) {\n",
" window._Plotly = Plotly;\n",
" });\n",
" }\n",
" </script>\n",
" "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
" <script type=\"text/javascript\">\n",
" window.PlotlyConfig = {MathJaxConfig: 'local'};\n",
" if (window.MathJax) {MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}\n",
" if (typeof require !== 'undefined') {\n",
" require.undef(\"plotly\");\n",
" requirejs.config({\n",
" paths: {\n",
" 'plotly': ['https://cdn.plot.ly/plotly-latest.min']\n",
" }\n",
" });\n",
" require(['plotly'], function(Plotly) {\n",
" window._Plotly = Plotly;\n",
" });\n",
" }\n",
" </script>\n",
" "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import pandas as pd\n",
"%matplotlib inline\n",
"import plotly.plotly as py\n",
"import plotly.graph_objs as go\n",
"from plotly.offline import iplot, init_notebook_mode\n",
"# Using plotly + cufflinks in offline mode\n",
"import cufflinks\n",
"cufflinks.go_offline(connected=True)\n",
"init_notebook_mode(connected=True)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-19T21:25:59.502360Z",
"start_time": "2019-08-19T21:25:59.456354Z"
}
},
"outputs": [],
"source": [
"df = pd.read_csv(\"belgium_data.csv\")\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-19T21:25:59.519470Z",
"start_time": "2019-08-19T21:25:59.506936Z"
}
},
"outputs": [],
"source": [
"df.columns = [\"Belgium\",\"Region\",\"Proportion of properties occupied by their owners\", \"Total amount of properties\", \"Total population\"]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-19T21:25:59.621626Z",
"start_time": "2019-08-19T21:25:59.528513Z"
}
},
"outputs": [],
"source": [
"df[\"Amount of properties not occupied by their owners\"] = round(df[\"Total amount of properties\"] * (1-\n",
"df[\"Proportion of properties occupied by their owners\"]))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-19T21:25:59.659037Z",
"start_time": "2019-08-19T21:25:59.625380Z"
}
},
"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>Belgium</th>\n",
" <th>Region</th>\n",
" <th>Proportion of properties occupied by their owners</th>\n",
" <th>Total amount of properties</th>\n",
" <th>Total population</th>\n",
" <th>Amount of properties not occupied by their owners</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Belgique</td>\n",
" <td>Région flamande</td>\n",
" <td>0.712</td>\n",
" <td>2584510</td>\n",
" <td>6325740</td>\n",
" <td>744339.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Belgique</td>\n",
" <td>Région de Bruxelles-Capitale</td>\n",
" <td>0.388</td>\n",
" <td>475619</td>\n",
" <td>1136778</td>\n",
" <td>291079.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Belgique</td>\n",
" <td>Région wallonne</td>\n",
" <td>0.662</td>\n",
" <td>1443065</td>\n",
" <td>3538120</td>\n",
" <td>487756.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Belgique</td>\n",
" <td>NaN</td>\n",
" <td>0.662</td>\n",
" <td>4503194</td>\n",
" <td>11000638</td>\n",
" <td>1522080.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Belgium Region \\\n",
"0 Belgique Région flamande \n",
"1 Belgique Région de Bruxelles-Capitale \n",
"2 Belgique Région wallonne \n",
"3 Belgique NaN \n",
"\n",
" Proportion of properties occupied by their owners \\\n",
"0 0.712 \n",
"1 0.388 \n",
"2 0.662 \n",
"3 0.662 \n",
"\n",
" Total amount of properties Total population \\\n",
"0 2584510 6325740 \n",
"1 475619 1136778 \n",
"2 1443065 3538120 \n",
"3 4503194 11000638 \n",
"\n",
" Amount of properties not occupied by their owners \n",
"0 744339.0 \n",
"1 291079.0 \n",
"2 487756.0 \n",
"3 1522080.0 "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-19T21:25:59.669764Z",
"start_time": "2019-08-19T21:25:59.661484Z"
}
},
"outputs": [],
"source": [
"df[\"Region\"].fillna(\"Belgique\", inplace=True)\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-19T21:25:59.694755Z",
"start_time": "2019-08-19T21:25:59.675220Z"
}
},
"outputs": [],
"source": [
"df_clean = df[[\"Region\",\"Total amount of properties\",\"Amount of properties not occupied by their owners\"]]\n",
"df_clean.sort_values('Amount of properties not occupied by their owners', inplace=True, ascending=False)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-19T21:26:00.513410Z",
"start_time": "2019-08-19T21:25:59.700753Z"
}
},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"linkText": "Export to plot.ly",
"plotlyServerURL": "https://plot.ly",
"showLink": true
},
"data": [
{
"marker": {
"color": "rgba(255, 153, 51, 0.6)",
"line": {
"color": "rgba(255, 153, 51, 1.0)",
"width": 1
}
},
"name": "Total amount of properties",
"orientation": "v",
"text": "",
"type": "bar",
"uid": "56a0ccb5-fd66-4d81-a2c0-ba350e682ba0",
"x": [
"Belgique",
"Région flamande",
"Région wallonne",
"Région de Bruxelles-Capitale"
],
"y": [
4503194,
2584510,
1443065,
475619
]
},
{
"marker": {
"color": "rgba(55, 128, 191, 0.6)",
"line": {
"color": "rgba(55, 128, 191, 1.0)",
"width": 1
}
},
"name": "Amount of properties not occupied by their owners",
"orientation": "v",
"text": "",
"type": "bar",
"uid": "39bc0cb5-3760-4851-96f1-bc9aa2862990",
"x": [
"Belgique",
"Région flamande",
"Région wallonne",
"Région de Bruxelles-Capitale"
],
"y": [
1522080,
744339,
487756,
291079
]
}
],
"layout": {
"legend": {
"bgcolor": "#F5F6F9",
"font": {
"color": "#4D5663"
}
},
"paper_bgcolor": "#F5F6F9",
"plot_bgcolor": "#F5F6F9",
"title": {
"font": {
"color": "#4D5663"
},
"text": "Belgium property renting market"
},
"xaxis": {
"gridcolor": "#E1E5ED",
"showgrid": true,
"tickfont": {
"color": "#4D5663"
},
"title": {
"font": {
"color": "#4D5663"
},
"text": ""
},
"zerolinecolor": "#E1E5ED"
},
"yaxis": {
"gridcolor": "#E1E5ED",
"showgrid": true,
"tickfont": {
"color": "#4D5663"
},
"title": {
"font": {
"color": "#4D5663"
},
"text": ""
},
"zerolinecolor": "#E1E5ED"
}
}
},
"text/html": [
"<div>\n",
" \n",
" \n",
" <div id=\"a81145dd-02aa-4c83-b8b8-c6e59fbd4694\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div>\n",
" <script type=\"text/javascript\">\n",
" require([\"plotly\"], function(Plotly) {\n",
" window.PLOTLYENV=window.PLOTLYENV || {};\n",
" window.PLOTLYENV.BASE_URL='https://plot.ly';\n",
" \n",
" if (document.getElementById(\"a81145dd-02aa-4c83-b8b8-c6e59fbd4694\")) {\n",
" Plotly.newPlot(\n",
" 'a81145dd-02aa-4c83-b8b8-c6e59fbd4694',\n",
" [{\"marker\": {\"color\": \"rgba(255, 153, 51, 0.6)\", \"line\": {\"color\": \"rgba(255, 153, 51, 1.0)\", \"width\": 1}}, \"name\": \"Total amount of properties\", \"orientation\": \"v\", \"text\": \"\", \"type\": \"bar\", \"uid\": \"56a0ccb5-fd66-4d81-a2c0-ba350e682ba0\", \"x\": [\"Belgique\", \"R\\u00e9gion flamande\", \"R\\u00e9gion wallonne\", \"R\\u00e9gion de Bruxelles-Capitale\"], \"y\": [4503194, 2584510, 1443065, 475619]}, {\"marker\": {\"color\": \"rgba(55, 128, 191, 0.6)\", \"line\": {\"color\": \"rgba(55, 128, 191, 1.0)\", \"width\": 1}}, \"name\": \"Amount of properties not occupied by their owners\", \"orientation\": \"v\", \"text\": \"\", \"type\": \"bar\", \"uid\": \"39bc0cb5-3760-4851-96f1-bc9aa2862990\", \"x\": [\"Belgique\", \"R\\u00e9gion flamande\", \"R\\u00e9gion wallonne\", \"R\\u00e9gion de Bruxelles-Capitale\"], \"y\": [1522080.0, 744339.0, 487756.0, 291079.0]}],\n",
" {\"legend\": {\"bgcolor\": \"#F5F6F9\", \"font\": {\"color\": \"#4D5663\"}}, \"paper_bgcolor\": \"#F5F6F9\", \"plot_bgcolor\": \"#F5F6F9\", \"title\": {\"font\": {\"color\": \"#4D5663\"}, \"text\": \"Belgium property renting market\"}, \"xaxis\": {\"gridcolor\": \"#E1E5ED\", \"showgrid\": true, \"tickfont\": {\"color\": \"#4D5663\"}, \"title\": {\"font\": {\"color\": \"#4D5663\"}, \"text\": \"\"}, \"zerolinecolor\": \"#E1E5ED\"}, \"yaxis\": {\"gridcolor\": \"#E1E5ED\", \"showgrid\": true, \"tickfont\": {\"color\": \"#4D5663\"}, \"title\": {\"font\": {\"color\": \"#4D5663\"}, \"text\": \"\"}, \"zerolinecolor\": \"#E1E5ED\"}},\n",
" {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\", \"responsive\": true}\n",
" ).then(function(){\n",
" \n",
"var gd = document.getElementById('a81145dd-02aa-4c83-b8b8-c6e59fbd4694');\n",
"var x = new MutationObserver(function (mutations, observer) {{\n",
" var display = window.getComputedStyle(gd).display;\n",
" if (!display || display === 'none') {{\n",
" console.log([gd, 'removed!']);\n",
" Plotly.purge(gd);\n",
" observer.disconnect();\n",
" }}\n",
"}});\n",
"\n",
"// Listen for the removal of the full notebook cells\n",
"var notebookContainer = gd.closest('#notebook-container');\n",
"if (notebookContainer) {{\n",
" x.observe(notebookContainer, {childList: true});\n",
"}}\n",
"\n",
"// Listen for the clearing of the current output cell\n",
"var outputEl = gd.closest('.output');\n",
"if (outputEl) {{\n",
" x.observe(outputEl, {childList: true});\n",
"}}\n",
"\n",
" })\n",
" };\n",
" });\n",
" </script>\n",
" </div>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"df_clean.iplot( kind = \"bar\", x='Region', title=\"Belgium property renting market\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-19T21:26:00.546040Z",
"start_time": "2019-08-19T21:26:00.517901Z"
}
},
"outputs": [],
"source": [
"df2 = pd.read_csv(\"brussels_data.csv\")\n",
"\n",
"df2 = df2[1:20]\n",
"df2.drop(df2.columns[[0,1,2]], axis=1, inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-19T21:26:00.560654Z",
"start_time": "2019-08-19T21:26:00.550205Z"
}
},
"outputs": [],
"source": [
"df2.columns = [\"Commune\",\"Proportion of properties occupied by their owners\", \"Total amount of properties\"]"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-19T21:26:00.579718Z",
"start_time": "2019-08-19T21:26:00.568070Z"
}
},
"outputs": [],
"source": [
"df2[\"Amount of properties not occupied by their owners\"] = round(df2[\"Total amount of properties\"] * (1-\n",
"df2[\"Proportion of properties occupied by their owners\"]))"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-19T21:26:00.616984Z",
"start_time": "2019-08-19T21:26:00.585476Z"
}
},
"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>Commune</th>\n",
" <th>Proportion of properties occupied by their owners</th>\n",
" <th>Total amount of properties</th>\n",
" <th>Amount of properties not occupied by their owners</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Anderlecht</td>\n",
" <td>0.411</td>\n",
" <td>41264</td>\n",
" <td>24304.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Auderghem</td>\n",
" <td>0.524</td>\n",
" <td>13841</td>\n",
" <td>6588.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Berchem-Sainte-Agathe</td>\n",
" <td>0.532</td>\n",
" <td>9021</td>\n",
" <td>4222.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Bruxelles</td>\n",
" <td>0.286</td>\n",
" <td>71801</td>\n",
" <td>51266.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Etterbeek</td>\n",
" <td>0.328</td>\n",
" <td>21061</td>\n",
" <td>14153.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Evere</td>\n",
" <td>0.433</td>\n",
" <td>15457</td>\n",
" <td>8764.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>Forest (Bruxelles-Capitale)</td>\n",
" <td>0.400</td>\n",
" <td>22901</td>\n",
" <td>13741.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Ganshoren</td>\n",
" <td>0.460</td>\n",
" <td>10708</td>\n",
" <td>5782.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Ixelles</td>\n",
" <td>0.289</td>\n",
" <td>42030</td>\n",
" <td>29883.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>Jette</td>\n",
" <td>0.476</td>\n",
" <td>20652</td>\n",
" <td>10822.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>Koekelberg</td>\n",
" <td>0.415</td>\n",
" <td>8369</td>\n",
" <td>4896.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>Molenbeek-Saint-Jean</td>\n",
" <td>0.378</td>\n",
" <td>33172</td>\n",
" <td>20633.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>Saint-Gilles</td>\n",
" <td>0.256</td>\n",
" <td>22341</td>\n",
" <td>16622.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>Saint-Josse-ten-Noode</td>\n",
" <td>0.294</td>\n",
" <td>9489</td>\n",
" <td>6699.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>Schaerbeek</td>\n",
" <td>0.382</td>\n",
" <td>46501</td>\n",
" <td>28738.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>Uccle</td>\n",
" <td>0.509</td>\n",
" <td>34366</td>\n",
" <td>16874.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>Watermael-Boitsfort</td>\n",
" <td>0.498</td>\n",
" <td>10579</td>\n",
" <td>5311.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>Woluwe-Saint-Lambert</td>\n",
" <td>0.443</td>\n",
" <td>24915</td>\n",
" <td>13878.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>Woluwe-Saint-Pierre</td>\n",
" <td>0.543</td>\n",
" <td>17151</td>\n",
" <td>7838.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Commune \\\n",
"1 Anderlecht \n",
"2 Auderghem \n",
"3 Berchem-Sainte-Agathe \n",
"4 Bruxelles \n",
"5 Etterbeek \n",
"6 Evere \n",
"7 Forest (Bruxelles-Capitale) \n",
"8 Ganshoren \n",
"9 Ixelles \n",
"10 Jette \n",
"11 Koekelberg \n",
"12 Molenbeek-Saint-Jean \n",
"13 Saint-Gilles \n",
"14 Saint-Josse-ten-Noode \n",
"15 Schaerbeek \n",
"16 Uccle \n",
"17 Watermael-Boitsfort \n",
"18 Woluwe-Saint-Lambert \n",
"19 Woluwe-Saint-Pierre \n",
"\n",
" Proportion of properties occupied by their owners \\\n",
"1 0.411 \n",
"2 0.524 \n",
"3 0.532 \n",
"4 0.286 \n",
"5 0.328 \n",
"6 0.433 \n",
"7 0.400 \n",
"8 0.460 \n",
"9 0.289 \n",
"10 0.476 \n",
"11 0.415 \n",
"12 0.378 \n",
"13 0.256 \n",
"14 0.294 \n",
"15 0.382 \n",
"16 0.509 \n",
"17 0.498 \n",
"18 0.443 \n",
"19 0.543 \n",
"\n",
" Total amount of properties \\\n",
"1 41264 \n",
"2 13841 \n",
"3 9021 \n",
"4 71801 \n",
"5 21061 \n",
"6 15457 \n",
"7 22901 \n",
"8 10708 \n",
"9 42030 \n",
"10 20652 \n",
"11 8369 \n",
"12 33172 \n",
"13 22341 \n",
"14 9489 \n",
"15 46501 \n",
"16 34366 \n",
"17 10579 \n",
"18 24915 \n",
"19 17151 \n",
"\n",
" Amount of properties not occupied by their owners \n",
"1 24304.0 \n",
"2 6588.0 \n",
"3 4222.0 \n",
"4 51266.0 \n",
"5 14153.0 \n",
"6 8764.0 \n",
"7 13741.0 \n",
"8 5782.0 \n",
"9 29883.0 \n",
"10 10822.0 \n",
"11 4896.0 \n",
"12 20633.0 \n",
"13 16622.0 \n",
"14 6699.0 \n",
"15 28738.0 \n",
"16 16874.0 \n",
"17 5311.0 \n",
"18 13878.0 \n",
"19 7838.0 "
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df2"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-19T21:26:00.639194Z",
"start_time": "2019-08-19T21:26:00.621371Z"
}
},
"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>Commune</th>\n",
" <th>Proportion of properties occupied by their owners</th>\n",
" <th>Total amount of properties</th>\n",
" <th>Amount of properties not occupied by their owners</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Bruxelles</td>\n",
" <td>0.286</td>\n",
" <td>71801</td>\n",
" <td>51266.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Etterbeek</td>\n",
" <td>0.328</td>\n",
" <td>21061</td>\n",
" <td>14153.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Ixelles</td>\n",
" <td>0.289</td>\n",
" <td>42030</td>\n",
" <td>29883.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>Saint-Gilles</td>\n",
" <td>0.256</td>\n",
" <td>22341</td>\n",
" <td>16622.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>Saint-Josse-ten-Noode</td>\n",
" <td>0.294</td>\n",
" <td>9489</td>\n",
" <td>6699.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Commune Proportion of properties occupied by their owners \\\n",
"4 Bruxelles 0.286 \n",
"5 Etterbeek 0.328 \n",
"9 Ixelles 0.289 \n",
"13 Saint-Gilles 0.256 \n",
"14 Saint-Josse-ten-Noode 0.294 \n",
"\n",
" Total amount of properties \\\n",
"4 71801 \n",
"5 21061 \n",
"9 42030 \n",
"13 22341 \n",
"14 9489 \n",
"\n",
" Amount of properties not occupied by their owners \n",
"4 51266.0 \n",
"5 14153.0 \n",
"9 29883.0 \n",
"13 16622.0 \n",
"14 6699.0 "
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df2[df2[\"Proportion of properties occupied by their owners\"]<0.35]"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-19T21:26:00.653668Z",
"start_time": "2019-08-19T21:26:00.644187Z"
}
},
"outputs": [],
"source": [
"# Sort by descending amount of properties\n",
"df2_clean = df2[[\"Commune\",\"Total amount of properties\",\"Amount of properties not occupied by their owners\"]]\n",
"df2_clean.sort_values('Amount of properties not occupied by their owners', inplace=True, ascending=False)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-19T21:26:00.668804Z",
"start_time": "2019-08-19T21:26:00.657883Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"154824.0"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Check how many of the most populated communes represent half of the renting market\n",
"df2_clean[\"Amount of properties not occupied by their owners\"][:5].sum()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"ExecuteTime": {
"end_time": "2019-08-19T21:26:00.893395Z",
"start_time": "2019-08-19T21:26:00.672211Z"
}
},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"linkText": "Export to plot.ly",
"plotlyServerURL": "https://plot.ly",
"showLink": true
},
"data": [
{
"marker": {
"color": "rgba(255, 153, 51, 0.6)",
"line": {
"color": "rgba(255, 153, 51, 1.0)",
"width": 1
}
},
"name": "Total amount of properties",
"orientation": "v",
"text": "",
"type": "bar",
"uid": "7a67e464-9e57-4929-8862-cbdd13a68ecf",
"x": [
"Bruxelles",
"Ixelles",
"Schaerbeek",
"Anderlecht",
"Molenbeek-Saint-Jean",
"Uccle",
"Saint-Gilles",
"Etterbeek",
"Woluwe-Saint-Lambert",
"Forest (Bruxelles-Capitale)",
"Jette",
"Evere",
"Woluwe-Saint-Pierre",
"Saint-Josse-ten-Noode",
"Auderghem",
"Ganshoren",
"Watermael-Boitsfort",
"Koekelberg",
"Berchem-Sainte-Agathe"
],
"y": [
71801,
42030,
46501,
41264,
33172,
34366,
22341,
21061,
24915,
22901,
20652,
15457,
17151,
9489,
13841,
10708,
10579,
8369,
9021
]
},
{
"marker": {
"color": "rgba(55, 128, 191, 0.6)",
"line": {
"color": "rgba(55, 128, 191, 1.0)",
"width": 1
}
},
"name": "Amount of properties not occupied by their owners",
"orientation": "v",
"text": "",
"type": "bar",
"uid": "ef17ae6b-cdf8-4278-ada3-27e177468a9d",
"x": [
"Bruxelles",
"Ixelles",
"Schaerbeek",
"Anderlecht",
"Molenbeek-Saint-Jean",
"Uccle",
"Saint-Gilles",
"Etterbeek",
"Woluwe-Saint-Lambert",
"Forest (Bruxelles-Capitale)",
"Jette",
"Evere",
"Woluwe-Saint-Pierre",
"Saint-Josse-ten-Noode",
"Auderghem",
"Ganshoren",
"Watermael-Boitsfort",
"Koekelberg",
"Berchem-Sainte-Agathe"
],
"y": [
51266,
29883,
28738,
24304,
20633,
16874,
16622,
14153,
13878,
13741,
10822,
8764,
7838,
6699,
6588,
5782,
5311,
4896,
4222
]
}
],
"layout": {
"legend": {
"bgcolor": "#F5F6F9",
"font": {
"color": "#4D5663"
}
},
"paper_bgcolor": "#F5F6F9",
"plot_bgcolor": "#F5F6F9",
"title": {
"font": {
"color": "#4D5663"
},
"text": "Brussels property renting market"
},
"xaxis": {
"gridcolor": "#E1E5ED",
"showgrid": true,
"tickfont": {
"color": "#4D5663"
},
"title": {
"font": {
"color": "#4D5663"
},
"text": ""
},
"zerolinecolor": "#E1E5ED"
},
"yaxis": {
"gridcolor": "#E1E5ED",
"showgrid": true,
"tickfont": {
"color": "#4D5663"
},
"title": {
"font": {
"color": "#4D5663"
},
"text": ""
},
"zerolinecolor": "#E1E5ED"
}
}
},
"text/html": [
"<div>\n",
" \n",
" \n",
" <div id=\"fc4fffde-6ab3-4e79-8620-cdcbff038a7e\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div>\n",
" <script type=\"text/javascript\">\n",
" require([\"plotly\"], function(Plotly) {\n",
" window.PLOTLYENV=window.PLOTLYENV || {};\n",
" window.PLOTLYENV.BASE_URL='https://plot.ly';\n",
" \n",
" if (document.getElementById(\"fc4fffde-6ab3-4e79-8620-cdcbff038a7e\")) {\n",
" Plotly.newPlot(\n",
" 'fc4fffde-6ab3-4e79-8620-cdcbff038a7e',\n",
" [{\"marker\": {\"color\": \"rgba(255, 153, 51, 0.6)\", \"line\": {\"color\": \"rgba(255, 153, 51, 1.0)\", \"width\": 1}}, \"name\": \"Total amount of properties\", \"orientation\": \"v\", \"text\": \"\", \"type\": \"bar\", \"uid\": \"7a67e464-9e57-4929-8862-cbdd13a68ecf\", \"x\": [\"Bruxelles\", \"Ixelles\", \"Schaerbeek\", \"Anderlecht\", \"Molenbeek-Saint-Jean\", \"Uccle\", \"Saint-Gilles\", \"Etterbeek\", \"Woluwe-Saint-Lambert\", \"Forest (Bruxelles-Capitale)\", \"Jette\", \"Evere\", \"Woluwe-Saint-Pierre\", \"Saint-Josse-ten-Noode\", \"Auderghem\", \"Ganshoren\", \"Watermael-Boitsfort\", \"Koekelberg\", \"Berchem-Sainte-Agathe\"], \"y\": [71801, 42030, 46501, 41264, 33172, 34366, 22341, 21061, 24915, 22901, 20652, 15457, 17151, 9489, 13841, 10708, 10579, 8369, 9021]}, {\"marker\": {\"color\": \"rgba(55, 128, 191, 0.6)\", \"line\": {\"color\": \"rgba(55, 128, 191, 1.0)\", \"width\": 1}}, \"name\": \"Amount of properties not occupied by their owners\", \"orientation\": \"v\", \"text\": \"\", \"type\": \"bar\", \"uid\": \"ef17ae6b-cdf8-4278-ada3-27e177468a9d\", \"x\": [\"Bruxelles\", \"Ixelles\", \"Schaerbeek\", \"Anderlecht\", \"Molenbeek-Saint-Jean\", \"Uccle\", \"Saint-Gilles\", \"Etterbeek\", \"Woluwe-Saint-Lambert\", \"Forest (Bruxelles-Capitale)\", \"Jette\", \"Evere\", \"Woluwe-Saint-Pierre\", \"Saint-Josse-ten-Noode\", \"Auderghem\", \"Ganshoren\", \"Watermael-Boitsfort\", \"Koekelberg\", \"Berchem-Sainte-Agathe\"], \"y\": [51266.0, 29883.0, 28738.0, 24304.0, 20633.0, 16874.0, 16622.0, 14153.0, 13878.0, 13741.0, 10822.0, 8764.0, 7838.0, 6699.0, 6588.0, 5782.0, 5311.0, 4896.0, 4222.0]}],\n",
" {\"legend\": {\"bgcolor\": \"#F5F6F9\", \"font\": {\"color\": \"#4D5663\"}}, \"paper_bgcolor\": \"#F5F6F9\", \"plot_bgcolor\": \"#F5F6F9\", \"title\": {\"font\": {\"color\": \"#4D5663\"}, \"text\": \"Brussels property renting market\"}, \"xaxis\": {\"gridcolor\": \"#E1E5ED\", \"showgrid\": true, \"tickfont\": {\"color\": \"#4D5663\"}, \"title\": {\"font\": {\"color\": \"#4D5663\"}, \"text\": \"\"}, \"zerolinecolor\": \"#E1E5ED\"}, \"yaxis\": {\"gridcolor\": \"#E1E5ED\", \"showgrid\": true, \"tickfont\": {\"color\": \"#4D5663\"}, \"title\": {\"font\": {\"color\": \"#4D5663\"}, \"text\": \"\"}, \"zerolinecolor\": \"#E1E5ED\"}},\n",
" {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\", \"responsive\": true}\n",
" ).then(function(){\n",
" \n",
"var gd = document.getElementById('fc4fffde-6ab3-4e79-8620-cdcbff038a7e');\n",
"var x = new MutationObserver(function (mutations, observer) {{\n",
" var display = window.getComputedStyle(gd).display;\n",
" if (!display || display === 'none') {{\n",
" console.log([gd, 'removed!']);\n",
" Plotly.purge(gd);\n",
" observer.disconnect();\n",
" }}\n",
"}});\n",
"\n",
"// Listen for the removal of the full notebook cells\n",
"var notebookContainer = gd.closest('#notebook-container');\n",
"if (notebookContainer) {{\n",
" x.observe(notebookContainer, {childList: true});\n",
"}}\n",
"\n",
"// Listen for the clearing of the current output cell\n",
"var outputEl = gd.closest('.output');\n",
"if (outputEl) {{\n",
" x.observe(outputEl, {childList: true});\n",
"}}\n",
"\n",
" })\n",
" };\n",
" });\n",
" </script>\n",
" </div>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"df2_clean.iplot( kind = \"bar\", x='Commune', title=\"Brussels property renting market\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"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.5"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"position": {
"height": "145px",
"left": "935px",
"right": "20px",
"top": "120px",
"width": "325px"
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment