import os
import pandas as pd
import pandas_profiling as pd_profiling
import altair as alt

def read_field_type(x):
    '''
    Para facilitar la lectura de los dataframes con los tipos de columna correspondientes.
    '''
    if x in ['String']:
        return str
    elif x in ['Integer', 'Long']:
        return int
    else:
        return str

spend_gob_names = pd.read_csv(os.path.join('data', 
                              'dataset_3_Revenue_and_ pending_(Central_Government)_Real_DICTIONARY.csv'), 
                              sep=';', 
                              encoding='iso-8859-1')

spend_gob_names

spend_gob = pd.read_csv(os.path.join('data', 
                              'dataset_3_Revenue_and_ pending_(Central_Government)_1990-2017 (real).csv'),
                 sep=';', 
                 encoding='iso-8859-1',
                 dtype=dict(zip(spend_gob_names['Field name'], spend_gob_names['Field type'].apply(read_field_type))))

spend_gob.columns = spend_gob.columns.str.lower()

spend_gob['real_amount'] = spend_gob['real_amount'].str.replace(',', '.').astype(float)

spend_gob.head(5) 

"""
Explanation: Datathon Mayo 2018  "Haciendo el gasto fiscal visible para el público"
Ingresos y Gastos anuales del Gobierno Central
Lectura de Datos
End of explanation
"""


spend_gob[spend_gob['real_amount'] < 0]

spend_gob['nivel2']

for col in s

"""
Explanation: Estadística Descriptiva
End of explanation
"""


cobre = spend_gob.query("nivel3 == 'Cobre bruto'")

alt.Chart(cobre).mark_bar().encode(
    x='periodo:O',
    y='sum(real_amount):Q',
    color='nivel3'
)

alt.Chart(spend_gob).mark_area().encode(
    x='periodo:O',
    y='sum(real_amount):Q',
    color='nivel3',
    column='nivel2'
)

"""
Explanation: Ejemplito
End of explanation
"""


