Skip to content

Instantly share code, notes, and snippets.

View dwillis's full-sized avatar

Derek Willis dwillis

View GitHub Profile

Keybase proof

I hereby claim:

  • I am dwillis on github.
  • I am dwillis (https://keybase.io/dwillis) on keybase.
  • I have a public key ASD4t9RUETMdUc4hZHex4IX442JaZQkZ8CF40PpFxKL4uwo

To claim this, I am signing this object:

@dwillis
dwillis / spatialite.md
Last active April 6, 2022 16:56
spatialite install

OSX

brew install libspatialite

geojson-to-sqlite toxmap.db hotspots hotspot_perimeters_for_data_store.geojson --spatialite

datasette toxmap.db --load-extension=spatialite

Windows

import os
import csv
from dateutil.parser import parse
from slack import WebClient
from slack.errors import SlackApiError
slack_token = os.environ["SLACK_API_TOKEN"]
client = WebClient(token=slack_token)
march_27 = parse('3/27/2022').date()
@dwillis
dwillis / group2_question_1.Rmd
Last active March 7, 2022 20:07
Calculating police shootings' gender percentage with guns
# create dataframe of all shootings by gender
all_police_shootings_by_gender <- fatal_police_shootings %>%
group_by(gender) %>%
summarise(count=n()) %>%
arrange(desc(count))
# create separate dataframes for each gender
all_shootings_men <- all_police_shootings_by_gender %>%
filter(gender == 'M')
Sample template for basic filtering, mutate and group_by with count
```{r}
my_result <- original_data %>%
filter(some_column == "some value") %>%
mutate(some_column=str_to_title(some_column)) %>%
group_by(some_column) %>%
summarise(new_aggregate = n()) %>%
arrange(desc(new_aggregate))
F3XNC00694323WINREDPO BOX 9891ARLINGTONVA22219MYP20222021010120210630OttenhoffBenjamin20210728506.45258275844.90258276351.35258275634.48716.870.00105821.00228991233.65826.00228992059.650.0098300.00229090359.650.000.000.000.0029185485.250.000.000.000.00258275844.90258275844.900.000.00615.58615.580.00229061108.650.000.000.000.0029185485.250.000.0029185485.2528425.000.000.000.000.00258275634.48258275634.48229090359.6529185485.25199904874.40615.580.00615.58506.452021258275844.90258276351.35258275634.48716.87228991233.65826.00228992059.650.0098300.00229090359.650.000.000.000.0029185485.250.000.000.000.00258275844.90258275844.900.000.00615.58615.580.00229061108.650.000.000.000.0029185485.250.000.0029185485.2528425.000.000.000.000.00258275634.48258275634.48229090359.6529185485.25199904874.40615.580.00615.58
allegany_sums_all <- allegany_athletics %>%
group_by(county, year) %>%
summarise(boys_total = sum(boys_participants), girls_total = sum(girls_participants)) %>%
select(county, year, boys_total, girls_total)
allegany_sums_without_cau <- allegany_athletics %>%
filter(is.na(type)) %>%
group_by(county, year) %>%
summarise(boys_without_cs = sum(boys_participants), girls_without_cs = sum(girls_participants)) %>%
select(county, year, boys_without_cs, girls_without_cs)
@dwillis
dwillis / merrill.r
Last active October 11, 2021 17:51
html <- read_html("https://merrill.umd.edu/about/faculty-and-staff")
# get faculty/staff names
names <- html %>% html_nodes(".card-title") %>% html_text()
length(faculty_staff)
faculty_staff[1]
# get titles
@dwillis
dwillis / example.R
Last active September 27, 2021 18:38
my_data %>%
mutate(
category = case_when(
amount < 10000 ~ 'under_10k',
amount < 50000 ~ '10k_50k',
amount < 100000 ~ '50k_100k',
amount < 500000 ~ '100k_500k',
amount < 1000000 ~ '500k_1m',
amount > 1000000 ~ '1m_plus'
)
library(tidyverse)
library(stringr)
library(fs)
results <- data.frame()
years <- c('2021','2020')
for (year in years) {
data_dir <- str_c("/Users/dwillis/code/wbb/fiba/", year)