This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script> | |
| <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> | |
| <script type="text/javascript"> | |
| function getAgeFromRUT(rut) { | |
| var today_date = new Date(); | |
| var slope = 3.3363697569700348e-06 | |
| var intercept = 1932.2573852507373 | |
| var birth_date = rut * slope + intercept | |
| var birth_date_year = Math.floor(birth_date) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import seaborn as sns; sns.set() | |
| import matplotlib.pyplot as plt | |
| flights = sns.load_dataset("flights");flights = flights.pivot("month", "year", "passengers") | |
| fig, ax = plt.subplots(1, figsize=(16,8)) | |
| sns.heatmap(flights, cbar=False, annot=True, fmt='.0f', ax=ax) | |
| for ix in range(12): # one per height | |
| x = range(12); y = ix+1-flights.iloc[ix]/flights.iloc[ix].max() | |
| h = plt.plot(x,y, lw=4) | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #/bin/bash | |
| sudo apt-get update | |
| sudo apt-get install -y docker.io | |
| sudo apt-get install -y docker-compose | |
| sudo systemctl start docker | |
| sudo systemctl enable docker | |
| docker --version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import folium, pandas as pd | |
| from folium.plugins import MarkerCluster | |
| pdf = pd.read_json('https://tinyurl.com/covid19-github') | |
| pdf = pdf[pdf.data==pdf.data.max()] | |
| pdf = pdf[pdf.totale_casi>0] | |
| centroid = pdf.describe()[['lat','long']].loc['50%'].values | |
| fm = folium.Map(location=centroid, zoom_start=6, tiles='stamentoner', | |
| width=800, height=600) | |
| mc = MarkerCluster() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import bonobo | |
| from sqlib import get_CAM_data, summarize, to_excel | |
| def Extracción(): | |
| data = get_CAM_data() | |
| print([(key,len(kdata)) for key, kdata in data.items()]) | |
| yield data | |
| def Transformación(): | |
| data['summary'] = summarize(data) # compute 2019/2020 stats |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sqlib import sql # acceso a BD local | |
| import seaborn as sns | |
| import matplotlib.pyplot as plt | |
| def heatmap(some_counts, title, value_var='N', annot_fontsize=24): | |
| fig, ax = plt.subplots(1, figsize=(24,12)) | |
| print(some_counts.columns) | |
| pivot = some_counts.pivot_table(index='producto', columns='AñoMes', values=value_var) | |
| p=sns.heatmap(pivot, annot=True, annot_kws={'size': annot_fontsize, | |
| 'weight': 'bold'}, fmt='.0f', cmap='jet') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import os | |
| #ticket = os.getenv('TOKEN_MP') | |
| from creds import ticket | |
| WAIT = 2; # segundos entre una y otra solicitud | |
| def get_OC(oc): | |
| BASE_MP = 'http://api.mercadopublico.cl/servicios/v1/publico/' | |
| url = f'{BASE_MP}/ordenesdecompra.json?codigo={oc}&ticket={ticket}' | |
| js = requests.get(url).json()['Listado'] | |
| return js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import requests, time, os | |
| TOKEN = os.getenv('TOKEN_MP') | |
| WAIT = 2 # this seems reasonable, 1 second does not work | |
| url = 's3://quantcldata/CLIENTS/ObservatorioFiscal/abril2020.csv' | |
| df = pd.read_csv(url) | |
| get_prod = lambda d: 'camilla' if 'camilla' in d else 'mascarilla' if 'mascarilla' in d else 'alcohol' if 'alcohol gel' in d else 'Otros' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json, pandas as pd | |
| df = pd.read_json('twitter_premium_api_Lemebel.json', orient = 'records', lines = True) | |
| df.head() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import seaborn as sns | |
| import matplotlib.pyplot as plt | |
| df = pd.read_csv('mobility.csv', encoding='latin-1') # this comes from Google Takeout in JSON format | |
| fig, ax = plt.subplots(1, figsize=(24,18)) | |
| p = sns.heatmap(df[df.año>2013].pivot_table(index='año', columns='mes', values='distancia'), | |
| annot=True, annot_kws = {'size':14, 'weight': 'bold'}, fmt='.1f', cmap='brg') | |
| _ = p.set_title('Kilómetros recorridos por Sergio Lucero al mes (según Google Maps)', size=24) | |
| plt.savefig('mobility.png', dpi=720) |