Skip to content

Instantly share code, notes, and snippets.

View andersonfrailey's full-sized avatar

andersonfrailey

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@andersonfrailey
andersonfrailey / turtle_90s_s.py
Created April 13, 2020 19:29
This script uses turtle to make that nifty little "S" thing we all used to draw in middle school a bunch of times
import turtle
import random
def draw_s(t, size=100, start=(0, 0), rel_gap=2):
"""
Draw the 90's S using turtle.
Parameters
----------
t: turtle object
# list to hold plot objects
plot_list = []
# loop through each year, creating a plot
for year in range(2018, 2028):
# advance calculators a year
calc.advance_to_year(year)
calc.calc_all()
calc_base.advance_to_year(year)
calc_base.calc_all()
def plot(cds_list, year):
def ticker():
"""
function used to create the y-axis labels in the plot
"""
if tick == 25:
return 'All Taxpayers'
elif tick == 21:
return '$1M or more'
elif tick == 18.75:
def find_perc(data, bin_name):
# find percentatge for each type of effect
sum_wt = data.s006.sum()
# tax liability decrease of > $500
large_cut = tc.zsum(data.s006[data['change'] < -500]) / float(sum_wt)
# tax liability decrease of $100-500
small_cut = tc.zsum(data.s006[(data['change'] >= -500) & (data['change'] <= -100)]) / float(sum_wt)
# tax liability change of less than $100
no_change = tc.zsum(data.s006[(data['change'] > -100) & (data['change'] < 100)]) / float(sum_wt)
# tax liability increase of $100-500
rec = tc.Records(data='../Tax-Calculator/puf.csv')
pol = tc.Policy()
calc_base = tc.Calculator(records=rec, policy=pol)
calc_base.advance_to_year(2018)
calc_base.calc_all()
records = tc.Records(data='../Tax-Calculator/puf.csv')
policy = tc.Policy()
calc = tc.Calculator(records=records, policy=policy)
from bokeh.plotting import figure
from bokeh.io import show, output_notebook
from bokeh.models import ColumnDataSource, Legend, FuncTickFormatter, NumeralTickFormatter
from bokeh.layouts import column
import taxcalc as tc
import pandas as pd
import numpy as np
import copy
output_notebook()
@andersonfrailey
andersonfrailey / api_call.py
Last active January 25, 2018 14:20
Places a call to the Code for DC Homeless Servaces Facilities data base and puts it in a Pandas DataFrame
"""
This script retreaves information on homeless services facilities from
http://opendata.dc.gov/datasets/homeless-service-facilities
"""
import requests
import pandas as pd
api_url = 'https://maps2.dcgis.dc.gov/dcgis/rest/services/DCGIS_DATA/Public_Service_WebMercator/MapServer/6/query?where=1%3D1&outFields=*&outSR=4326&f=json'
raw_data = requests.get(api_url)