Skip to content

Instantly share code, notes, and snippets.

View WalkerHarrison's full-sized avatar

Walker Harrison WalkerHarrison

View GitHub Profile
extras <- do.call(data.frame, aggregate(tree_dbh ~ zipcode, trees,
FUN=function(x) c(mn = mean(x), count = length(x))))
neighborhoods <- merge(neighborhoods, extras, by="zipcode")
neighborhoods$trees_per_capita <- neighborhoods$tree_dbh.count/neighborhoods$population
ggplot(neighborhoods,
aes(x=income, y=tree_dbh.mn, size = trees_per_capita, label=neighborhoods$zipcode)) +
geom_point(color="green") + geom_smooth(method='lm',formula=y~x, show.legend =F) +
geom_text(size=4, nudge_x = 1300, nudge_y = c(0.1, -0.1, -0.1)) +
scale_size_continuous(range=c(0,10)) +
library(XML)
library(ggplot2)
library(ggmap)
library(RSocrata)
url_trees <- 'https://data.cityofnewyork.us/resource/nwxe-4ae8.csv'
url_zips <- 'http://zipatlas.com/us/ny/brooklyn/zip-code-comparison/median-household-income.htm'
trees <-read.socrata(url_trees)
trees <- subset(trees, boroname == 'Brooklyn')
d = {"search": searches,
"time": dates}
googled = pd.DataFrame(d)
dt = datetime.datetime(2014, 10, 1)
end = datetime.datetime(2017, 3, 5)
step = datetime.timedelta(days=7)
weekly = []
combo = ' '.join(searches)
freqs = Counter(combo.split())
top = freqs.most_common(40)
words = []
counts = []
for i in range(40):
words.append(top[i][0])
counts.append(top[i][1])
hours = [datetime.datetime.strptime(i, '%Y-%m-%d %H:%M:%S').hour for i in dates]
n, bins, patches = plt.hist(hours, 24, facecolor='blue', alpha=0.75)
plt.xticks([0,6,12,18], ['12 AM','6 AM', '12 PM', '6 PM'], fontsize=18)
plt.xlabel('Hour', fontsize=24)
plt.ylabel('Frequency', fontsize=24)
plt.gcf().set_size_inches(18.5, 10.5, forward=True)
plt.show()
import json
import os
import datetime
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from collections import Counter
files= os.listdir('Searches')
del files[0]