In [1]:
import pandas as pd
import numpy as np
import plotly
from plotly.graph_objs import * # todo remove redundant imports
import plotly.plotly as py
import plotly.graph_objs as go
from plotly import tools

import sys
sys.path.append('../../src/')
from utils.database import dbutils

connection = dbutils.connect()

In [15]:
def stacked_bar_chart(df, filename, title=''):
    data = []
    print(df.columns.values)
    df['Europe'] = df['benelux'] + df['scandinavia'] + df['balkans'] + df['eastern_europe'] + df['netherlands']
    for country in list(df.columns.values):
        trace = Bar(
            x=df['visit_date'],
            y=df[country],
            name=country
        )

        data.append(trace)

    layout = go.Layout(
        barmode='stack',
        bargap=0,
        title=title,
        xaxis=dict(
            fixedrange=True
        ),
        yaxis=dict(
            title='Number of Visitors',
            fixedrange=True
        )
    )
    
    fig = go.Figure(data=data, layout=layout)
    return py.iplot(fig, filename=filename, sharing='private')

In [16]:
ae_query = """
SELECT * from optourism.info_center_ae_daily
"""
ae_center = pd.read_sql(ae_query, con=connection)

stacked_bar_chart(ae_center, 'infocenter_ae_visitors_by_nationality', title="Total Number of Visitors to the Airport Info Center by Nationality")


['visit_date' 'italy' 'spain_portugal' 'france' 'uk_ireland' 'netherlands'
 'benelux' 'germany' 'scandinavia' 'poland' 'eastern_europe' 'balkans'
 'russia' 'canada' 'usa' 'central_america' 'brasil' 'argentina'
 'south_america' 'australia_nz' 'turkey' 'israel' 'middle_east' 'india'
 'china' 'south_korea' 'japan' 'asia' 'south_africa' 'africa']
Out[16]: