Skip to content

Instantly share code, notes, and snippets.

@drcjar
Created November 7, 2016 17:11
Show Gist options
  • Save drcjar/465d4c95b132e8fc2132cc9960ceeee0 to your computer and use it in GitHub Desktop.
Save drcjar/465d4c95b132e8fc2132cc9960ceeee0 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": false
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import xlrd\n",
"import folium\n",
"import json"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#map from here https://www.sharegeo.ac.uk/handle/10672/305?show=full\n",
"#data from here http://www.hse.gov.uk/statistics/tables/mesoarea.xlsx"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df = pd.read_excel('mesoarea.xlsx', sheetname='mesoarea02', skiprows=4)\n",
"\n",
"with open('localua.geojson') as data_file:\n",
" data = json.load(data_file)\n",
"\n",
"geo_names = []\n",
"\n",
"for feature in data['features']:\n",
" geo_names.append(feature['properties']['NAME'])\n",
" \n",
"df1 = df[['Area']]\n",
"df2 = pd.DataFrame(geo_names)\n",
"df2.columns =['geo_names']"
]
},
{
"cell_type": "code",
"execution_count": 8,
"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>Area</th>\n",
" <th>geo_names</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>NaN</td>\n",
" <td>Wycombe District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>GREAT BRITAIN</td>\n",
" <td>South Bucks District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>ENGLAND &amp; WALES</td>\n",
" <td>Chiltern District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>ENGLAND</td>\n",
" <td>Aylesbury Vale District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>NORTH EAST</td>\n",
" <td>Fenland District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>County Durham UA1</td>\n",
" <td>South Cambridgeshire District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Darlington UA</td>\n",
" <td>East Cambridgeshire District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>Hartlepool UA</td>\n",
" <td>Huntingdonshire District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Middlesbrough UA</td>\n",
" <td>Cambridge District (B)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Northumberland UA2</td>\n",
" <td>Copeland District (B)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>Redcar And Cleveland UA</td>\n",
" <td>Carlisle District (B)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>Stockton-On-Tees UA</td>\n",
" <td>South Lakeland District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>Tyne And Wear (Met County)</td>\n",
" <td>Allerdale District (B)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>Gateshead</td>\n",
" <td>Eden District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>Newcastle-Upon-Tyne</td>\n",
" <td>Barrow-in-Furness District (B)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>North Tyneside</td>\n",
" <td>High Peak District (B)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>South Tyneside</td>\n",
" <td>South Derbyshire District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>Sunderland</td>\n",
" <td>Erewash District (B)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>NORTH WEST</td>\n",
" <td>North East Derbyshire District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>Blackburn With Darwen UA</td>\n",
" <td>Amber Valley District (B)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>Blackpool UA</td>\n",
" <td>Bolsover District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>Cheshire East UA3</td>\n",
" <td>Derbyshire Dales District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>Cheshire West &amp; Chester UA4</td>\n",
" <td>Chesterfield District (B)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>Halton UA</td>\n",
" <td>North Devon District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>Warrington UA</td>\n",
" <td>East Devon District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>Cumbria</td>\n",
" <td>Teignbridge District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>Allerdale</td>\n",
" <td>West Devon District (B)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>Barrow-In-Furness</td>\n",
" <td>Mid Devon District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>Carlisle</td>\n",
" <td>Exeter District (B)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>Copeland</td>\n",
" <td>Purbeck District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>410</th>\n",
" <td>Eilean Siar (Western Isles) UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>411</th>\n",
" <td>Falkirk UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>412</th>\n",
" <td>Fife UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>413</th>\n",
" <td>Glasgow City UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>414</th>\n",
" <td>Highland UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>415</th>\n",
" <td>Inverclyde UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>416</th>\n",
" <td>Midlothian UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>417</th>\n",
" <td>Moray UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>418</th>\n",
" <td>North Ayrshire UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>419</th>\n",
" <td>North Lanarkshire UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>420</th>\n",
" <td>Orkney Islands UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>421</th>\n",
" <td>Perth And Kinross UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>422</th>\n",
" <td>Renfrewshire UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>423</th>\n",
" <td>Scot Borders, The UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>424</th>\n",
" <td>Shetland Islands UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>425</th>\n",
" <td>South Ayrshire UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>426</th>\n",
" <td>South Lanarkshire UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>427</th>\n",
" <td>Stirling UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>428</th>\n",
" <td>West Dunbartonshire UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>429</th>\n",
" <td>West Lothian UA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>430</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>431</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>432</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>433</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>434</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>435</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>436</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>437</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>438</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>439</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>440 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" Area geo_names\n",
"0 NaN Wycombe District\n",
"1 GREAT BRITAIN South Bucks District\n",
"2 ENGLAND & WALES Chiltern District\n",
"3 ENGLAND Aylesbury Vale District\n",
"4 NORTH EAST Fenland District\n",
"5 County Durham UA1 South Cambridgeshire District\n",
"6 Darlington UA East Cambridgeshire District\n",
"7 Hartlepool UA Huntingdonshire District\n",
"8 Middlesbrough UA Cambridge District (B)\n",
"9 Northumberland UA2 Copeland District (B)\n",
"10 Redcar And Cleveland UA Carlisle District (B)\n",
"11 Stockton-On-Tees UA South Lakeland District\n",
"12 Tyne And Wear (Met County) Allerdale District (B)\n",
"13 Gateshead Eden District\n",
"14 Newcastle-Upon-Tyne Barrow-in-Furness District (B)\n",
"15 North Tyneside High Peak District (B)\n",
"16 South Tyneside South Derbyshire District\n",
"17 Sunderland Erewash District (B)\n",
"18 NORTH WEST North East Derbyshire District\n",
"19 Blackburn With Darwen UA Amber Valley District (B)\n",
"20 Blackpool UA Bolsover District\n",
"21 Cheshire East UA3 Derbyshire Dales District\n",
"22 Cheshire West & Chester UA4 Chesterfield District (B)\n",
"23 Halton UA North Devon District\n",
"24 Warrington UA East Devon District\n",
"25 Cumbria Teignbridge District\n",
"26 Allerdale West Devon District (B)\n",
"27 Barrow-In-Furness Mid Devon District\n",
"28 Carlisle Exeter District (B)\n",
"29 Copeland Purbeck District\n",
".. ... ...\n",
"410 Eilean Siar (Western Isles) UA NaN\n",
"411 Falkirk UA NaN\n",
"412 Fife UA NaN\n",
"413 Glasgow City UA NaN\n",
"414 Highland UA NaN\n",
"415 Inverclyde UA NaN\n",
"416 Midlothian UA NaN\n",
"417 Moray UA NaN\n",
"418 North Ayrshire UA NaN\n",
"419 North Lanarkshire UA NaN\n",
"420 Orkney Islands UA NaN\n",
"421 Perth And Kinross UA NaN\n",
"422 Renfrewshire UA NaN\n",
"423 Scot Borders, The UA NaN\n",
"424 Shetland Islands UA NaN\n",
"425 South Ayrshire UA NaN\n",
"426 South Lanarkshire UA NaN\n",
"427 Stirling UA NaN\n",
"428 West Dunbartonshire UA NaN\n",
"429 West Lothian UA NaN\n",
"430 NaN NaN\n",
"431 NaN NaN\n",
"432 NaN NaN\n",
"433 NaN NaN\n",
"434 NaN NaN\n",
"435 NaN NaN\n",
"436 NaN NaN\n",
"437 NaN NaN\n",
"438 NaN NaN\n",
"439 NaN NaN\n",
"\n",
"[440 rows x 2 columns]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.concat([df1, df2], axis=1) #need to marry up Area from meso file with geo_names from map file before can have pretty pictures"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"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.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment