import os

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

import seaborn

%matplotlib inline

font = {'family' : 'monospace',
        'weight' : 'bold',
        'size'   : 14}

plt.rc('font', **font)
plt.rc('figure', figsize=(18, 6))

os.chdir('../datasets/open-supermarkets/')

supermarkets = pd.read_csv('GeoLytixOpenSupermarketLocationsSept2015v6.txt', sep='\t')

supermarkets.head()

"""
Explanation: http://geolytix.co.uk/blog/category/open-data/supermarket-locations/
End of explanation
"""


vc = supermarkets['Retailer'].value_counts()[:10]  # keep the top-10

idx = np.arange(len(vc.index))
plt.bar(
    idx, vc.values, tick_label=vc.index, align='center'
)

from ipywidgets import HTML

HTML('<iframe width="100%" height="520" frameborder="0" '
     'src="https://additionplus.cartodb.com/viz/cf091c2c-d4f0-11e5-a5e6-0ef24382571b/embed_map" '
     'allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen legend'
     '></iframe>')

"""
Explanation: Visualise
End of explanation
"""


labour_market = pd.read_csv('regional_labour_market_li02_2016-01.csv').dropna()

labour_market.head()

"""
Explanation: Enrich with the regional labour market data
Regional labour market: LI02 - Local indicators for parliamentary constituencies, January 2016 (Excel sheet 314Kb)
End of explanation
"""


joined = supermarkets.merge(labour_market, left_on='Town', right_on='region', how='outer')

labour_market[labour_market['region'] == 'Hatfield']

"""
Explanation: Join on town
End of explanation
"""


