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
def gmap(lat,lon,zoom=14): | |
from IPython.display import IFrame | |
from IPython.core.display import display | |
# Google Maps URL template for an iframe | |
google_maps_url = "http://maps.google.com/maps?q={0}+{1}&" + \ | |
"ie=UTF8&t=h&z={2}&{0},{1}&output=embed".format(lat, lon,zoom) |
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 pip | |
from subprocess import call | |
for dist in pip.get_installed_distributions(): | |
call("pip install --upgrade " + dist.project_name, shell=True) |
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 math | |
def distance_on_unit_sphere(lat1, long1, lat2, long2): | |
# Convert latitude and longitude to | |
# spherical coordinates in radians. | |
degrees_to_radians = math.pi/180.0 | |
# phi = 90 - latitude | |
phi1 = (90.0 - lat1)*degrees_to_radians |
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
def trim_par(line): | |
outp = [] | |
comp=re.compile(r'\(+\S+\)', re.IGNORECASE) | |
linesplit=line.split() | |
for index in range(0, len(linesplit)): | |
m = comp.search(linesplit[index]) | |
if m: | |
continue | |
else: | |
outp.append(linesplit[index] |
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
#Reject entries containing non-alphanumeric chars | |
if re.match('^[a-zA-Z0-9_]+$', test1): | |
#do stuff |
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
def res_clean(line): | |
#set name entry equal to label if broken | |
n = re.match('^[a-zA-Z0-9_]+$',line["name"]) | |
if line["name"]=="NULL" or not n: | |
line["name"]=line["rdf-schema#label"] | |
#if value is null set to none | |
for key, value in line.items(): | |
if value=="NULL": | |
line[key]=None | |
#trim redundant parentheses from rdf-schema#label |
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
def get_IA_pop_dens_ZIP(): | |
#scrapes table from http://zipatlas.com/us/ia/zip-code-comparison/population-density.htm | |
#and http://zipatlas.com/us/ia/zip-code-comparison/population-density.?.htm | |
url_base = "http://zipatlas.com/us/ia/zip-code-comparison/" | |
page1 = "population-density." | |
pnum = [i for i in range(1,11)] | |
htm = "htm" | |
tables_pages =[] | |
for page in pnum: | |
if page==1: |
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
#Took this function that makes nice correlation tables from here | |
#http://myowelt.blogspot.co.uk/2008/04/beautiful-correlation-tables-in-r.html | |
corstarsl <- function(x){ | |
require(Hmisc) | |
x <- as.matrix(x) | |
R <- rcorr(x)$r | |
p <- rcorr(x)$P | |
## define notions for significance levels; spacing is important. | |
mystars <- ifelse(p < .001, "***", ifelse(p < .01, "** ", ifelse(p < .05, "* ", " "))) |
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
#Adjusted from http://www.r-bloggers.com/how-to-make-a-histogram-with-ggplot2/ | |
ggplot(data=data1, aes(x=`BOTTLE QTY`)) + | |
geom_histogram(aes(y =..density..), | |
col="red", | |
fill="green", | |
alpha = .2, origin = -0.5, binwidth=1) + | |
labs(title="Histogram for Bottle Quantities") + | |
labs(x="Bottles", y="Count") + scale_x_continuous(limits=c(0,30), breaks=0: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
require("RSQLite") | |
# Set up database | |
drv <- dbDriver("SQLite") | |
tfile <- "Iowa.db" | |
con <- dbConnect(drv, dbname = "Iowa.db") | |
dbWriteTable(con, "data1", as.data.frame(data1)) | |
dbDisconnect(con) |
OlderNewer