Skip to content

Instantly share code, notes, and snippets.

Avatar

Sergio Lucero sergiolucero

View GitHub Profile
View interpoladorFechas.js
<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)
View lined_heatmap.py
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()
View docker_install.sh
#/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
View mapa_covid_italia.py
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()
@sergiolucero
sergiolucero / bonobo_CAM.py
Created Apr 22, 2020
bonobo productos COVID-19
View bonobo_CAM.py
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
@sergiolucero
sergiolucero / mercado_heatmap.py
Last active Apr 21, 2020
heatmap Mercado Público
View mercado_heatmap.py
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')
View mercado_publico.py
#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
@sergiolucero
sergiolucero / scraper_mercado_publico.py
Last active Apr 20, 2020
Scraper Mercado Público
View scraper_mercado_publico.py
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'
@sergiolucero
sergiolucero / leemela_torero.py
Created Apr 15, 2020
Como leer Torero desde Pandas
View leemela_torero.py
import json, pandas as pd
df = pd.read_json('twitter_premium_api_Lemebel.json', orient = 'records', lines = True)
df.head()
@sergiolucero
sergiolucero / timeline_km_counter.py
Created Apr 9, 2020
Plotting total travel from my Google Location History
View timeline_km_counter.py
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)
You can’t perform that action at this time.