This file contains 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 | |
import geopandas as gp | |
import requests | |
data = requests.get('http://sergiolucerovera.pythonanywhere.com/static/chile.shp') | |
chile = gp.GeoDataFrame(data.json()) | |
elihc = None # use geopandas.read_file?? | |
centroid = [(cc[1],cc[0]) for cc in chile.centroid] | |
cmap = folium(location=centroid, zoom=15, tiles='Staro_Pramen') |
This file contains 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 openaq | |
parameters = ['co', 'no2', 'o3', 'pm10', 'pm25', 'so2'] | |
api = openaq.OpenAQ() | |
country_list = api.countries(df=True) | |
print('MONITORING %d locations worldwide' %(country_list.locations.sum())) | |
for cid, cdata in country_list.iterrows(): | |
ctry = cdata.name |
This file contains 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 geopandas as gp | |
import folium | |
# Fuentes SHAPEFILES... http://www.ide.cl/descarga/capas.html | |
# src: https://ocefpaf.github.io/python4oceanographers/blog/2015/02/02/cartopy_folium_shapefile/ |
This file contains 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 pandasqlutils import * # to easily cross tables | |
bikes = pd.read_url('http://quant.cl/db/bikes') # serving from quant via sqlite | |
airquality = pd.read_url('s3://amazonxyz.aws.com/sdakjldajds') # using an S3 bucket | |
weather = pd.read_url('quant.cl/postgres/weather' # running on a docker (Rad?) | |
airvsclimate = cross(airquality, weather) | |
print(airvsclimate.head()) |
This file contains 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 wikipedia | |
CITIES=['Paris','Barcelona','Tokyo', 'New York City','Amsterdam','Copenhaguen','San Francisco'] | |
AMBIGUOUS_CITIES = ['Santiago'] | |
for city in CITIES: | |
citywiki = wikipedia.page(city) | |
cwsum = citywiki.summary | |
poploc = cwsum.index('population') # first and only? use re! | |
print(city, cwsum[poploc:poploc+30]) |
This file contains 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 googlemaps | |
GMAPS_API = 'AIzaSyBjB7GbQ2TL2SUW989uu7ZoP6S0bxsv3t8' # EKHOS July 2017 | |
gmaps = googlemaps.Client(key=GMAPS_API) | |
gref = gmaps.geocode('Emilio Vaisse 564, Providencia') | |
print(gref[0]['geometry']) |
This file contains 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
library(tm);library(wordcloud);library(memoise) | |
books <<- list("A Mid Summer Night's Dream" = "summer", | |
"Glamorama" = "Glamorama1") # The list of valid books | |
getTermMatrix <- memoise(function(book) { # Using "memoise" to automatically cache the results | |
if (!(book %in% books)) stop("Unknown book") | |
text <- readLines(sprintf("./%s.txt.gz", book), encoding="UTF-8") | |
myCorpus = Corpus(VectorSource(text)) |
This file contains 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 | |
import pandas as pd | |
import urllib.request | |
ori='75+9th+Ave+New+York,+NY' | |
des='MetLife+Stadium+1+MetLife+Stadium+Dr+East+Rutherford,+NJ+07073' | |
dep=int(datetime.datetime.now().timestamp()) | |
URL='https://maps.googleapis.com/maps/api/directions/json?origin=%s&destination=%s&departure_time=%d' %(ori,des,dep) | |
URL+='&traffic_model=best_guess&key=AIzaSyB_ZS04dfON0PZVBRwhKTkeChK3rlYUgSk' |
This file contains 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 forestry import ForestryLinearProgram # this is project-specific | |
from PuLP.solvers import CBC # open-source LinearProgramming library and solver | |
from creds import BASE_URL, API_KEY # these are used to id with IBM | |
from docloud.job import JobClient | |
my_problem = ForestryLinearProgram('forestry_test.xlsx') # input file contains all relevant tree data | |
#my_problem.solve(CBC) # this is how we used to work, until our problems grew too big for open-source | |
my_problem.save_to_MPS('forestry_LP.mps') # here we export to a format that IBM CPLEX can recognize |
This file contains 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 selenium import webdriver | |
url='http://consultawebvehiculos.carabineros.cl/index.php' | |
fd = webdriver.Firefox() | |
plates = ['CZJB81','BDPW78'] | |
sections = ['txtLetras','txtNumeros1','txtNumeros2'] | |
def check_robo(patente): | |
fd.get(url) # point to the starting page again | |
patsplit = [patente[:2],patente[2:4], patente[4:]] | |
for ix, sec in enumerate(sections): |