import pandas as pd
import numpy as np
import scipy as sp
import plotly.plotly as py
import plotly.figure_factory as ff
import plotly
plotly.tools.set_credentials_file(username='gastudillo', api_key='OiqcwUGj4Jmtn1KtY6oR')

"""
Explanation: Prueba de generación de gráficos
Primero, hay que incluir los paquetes pandas, numpy, scipy y plotly.
Para crear las credenciales para plotly, de debe ir a https://plot.ly/settings/api. Luego, el username y el api_key se deben guardar en el archivo ~/.plotly/.credentials
End of explanation
"""


df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/school_earnings.csv")

table = ff.create_table(df)

py.iplot(table, filename='table1')

schools = df.School

print(schools[0],";" ,schools[1])

"""
Explanation: Luego, importar los datos
End of explanation
"""


df.std()

"""
Explanation: La función std() calcula la desviación estándar de cada columna
End of explanation
"""


df.mean()

"""
Explanation: La función mean() calcula la desviación estándar de cada columna
End of explanation
"""


from plotly.graph_objs import *

"""
Explanation: Para generar gráficos, hay que importar los tipos de gráficos disponibles:
End of explanation
"""


data = [Bar(x=df.School,
            y=df.gap)]

py.iplot(data, filename='basic_bar')

trace_women = Bar(x=df.School,
                  y=df.Women,
                  name='Women',
                  marker=dict(color='#ffcdd2'))

trace_men = Bar(x=df.School,
                y=df.Men,
                name='Men',
                marker=dict(color='#A2D5F2'))

trace_gap = Bar(x=df.School,
                y=df.gap,
                name='Gap',
                marker=dict(color='#59606D'))

data = [trace_women, trace_men, trace_gap]
layout = Layout(title="Average Earnings for Graduates",
                xaxis=dict(title='School'),
                yaxis=dict(title='Salary (in thousands)'))
fig = Figure(data=data, layout=layout)

py.iplot(fig, filename='simple_styled_bar')

"""
Explanation: Luego, se puede generar, por ejemplo, un gráfico de barra
End of explanation
"""


