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 requests, pandas as pd | |
| from bs4 import BeautifulSoup | |
| url_base = 'https://nuevo.jumbo.cl/%s' | |
| def parse(what): | |
| print(what) | |
| bs = BeautifulSoup(requests.get(url_base %what).text, 'lxml') | |
| producto = [pt.text.split(chr(10))[1] for pt in bs.find_all('div',attrs={'class':'product-item__info'})] | |
| marca = [pt.text.split(chr(10))[2] for pt in bs.find_all('div',attrs={'class':'product-item__info'})] |
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 aiohttp | |
| import asyncio | |
| import time, pandas as pd | |
| def async_http_get(urls, extractor=None, json_response=True): | |
| tasks = [] | |
| sem = asyncio.Semaphore(32) | |
| async def fetch(session, url): | |
| async with session.get(url) as response: |
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 datetime import datetime | |
| from pytz import timezone | |
| def chile_time(): | |
| scl = timezone('America/Santiago') | |
| scl_time = datetime.now(scl) | |
| return scl_time.strftime('%Y-%m-%d %H-%M-%S') |
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 | |
| from token import TOKEN # token personal: http://www.energiaabierta.cne.cl/ | |
| TIPOS = ['calefaccion','vehicular'] | |
| SOURCE = 'http://api.cne.cl/v3/combustibles/{}/estaciones?token={}' | |
| COPY_VARS = ['nombre_comuna', 'id_region', 'direccion_calle', 'fecha_hora_actualizacion'] | |
| for tipo in TIPOS: | |
| print(tipo) | |
| df = pd.read_json(SOURCE.format(tipo, TOKEN)) | |
| out = pd.DataFrame() |
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 creds import ID,CODE # isolines: driving from my house | |
| import folium | |
| import requests | |
| home =[-33.406654,-70.572701] # 085 LOS MILITARES / ALONSO DE CORDOVA | |
| head = 'https://isoline.route.cit.api.here.com/routing/7.2/calculateisoline.json?' | |
| URL_BASE = '{}app_id={}&app_code={}&mode=shortest;car;traffic:disabled&start=geo!{},{}&range={}&rangetype={}' | |
| def isodata(home, range, type): |
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 google.colab import files;uploaded = files.upload() | |
| #!pip install TPOT | |
| from tpot import TPOTRegressor | |
| from sklearn.model_selection import train_test_split | |
| df=pd.read_csv('32928_chile_autos.csv') | |
| df=df[(df.A帽o>1980)&(df.Kilometraje>1000)&(df.Precio<100000000)&(df.Precio>1000000)] | |
| data_columns = df.columns[2:-1] # add some more! | |
| target_columns = df.columns[-1] # use logs! | |
| X,y = df[data_columns], df[target_columns] |
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
| gdf=pysqldf('SELECT semana,Oficina,AVG(Tiempo_Ate_Min) AS TiempoAtencion, \ | |
| AVG(Tiempo_Esp_Min) AS TiempoEspera,\ | |
| COUNT(DISTINCT(Ejecutivo)) AS Personal FROM df GROUP BY Oficina, semana') | |
| atencion = gdf.pivot("Oficina","semana", "TiempoAtencion") | |
| espera = gdf.pivot("Oficina","semana", "TiempoEspera") | |
| ejecutivos = gdf.pivot("Oficina","semana", "Personal") # on same plot? | |
| f, (ax1, ax2, ax3) = plt.subplots(1,3,figsize=(20, 8),sharey=True) | |
| sns.heatmap(atencion, cmap="rainbow",fmt="d",ax=ax1) | |
| sns.heatmap(espera, cmap="rainbow",fmt="d",ax=ax2) |
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
| #!wget https://www.bcn.cl/siit/obtienearchivo?id=repositorio/10221/10396/1/division_comunal.zip | |
| #!mv obtienearchivo\?id\=repositorio%2F10221%2F10396%2F1%2Fdivision_comunal.zip comunal.zip | |
| #!unzip comunal | |
| #!pip install geopandas | |
| import geopandas as gp | |
| df = gp.read_file('division_comunal.shp') | |
| #df.NOM_REG.unique() | |
| rmdf = df[df.NOM_REG=='Regi贸n Metropolitana de Santiago'] | |
| print('Procesamos %d comunas en la Regi贸n Metropolitana' %len(rmdf)) | |
| rmdf.to_pickle('rm.pk') # 780K! upload to quant.cl for reference (just repeat the above) |
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
| BIKE_URL = 'https://api.citybik.es/v2/networks?fields=id,location,href' | |
| HERE_URL = '''https://route.cit.api.here.com/routing/7.2/calculateroute.json? | |
| app_id=arVngf4Gl3gIU145UGVB&app_code=Pas2aQELd9IynApEQ4m8jg& | |
| waypoint0=geo!52.5,13.4&waypoint1=geo!52.5,13.45& | |
| mode=fastest;bicycle''' # or car | |
| BACKUP = 'https://github.com/sergiolucero/hereapi/blob/master/DATA/bikesystems.csv' |
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
| 'use strict'; | |
| module.exports.hello = (event, context, callback) => { | |
| const response = { | |
| statusCode: 200, | |
| body: JSON.stringify({ | |
| message: 'hola Sergio!', | |
| }), | |
| }; | |
| callback(null, response); | |
| }; |