Skip to content

Instantly share code, notes, and snippets.

View drkane's full-sized avatar

David Kane drkane

View GitHub Profile
@drkane
drkane / la_codes_2011_2019.json
Last active January 29, 2020 13:03
Mapping ONS geocodes for local authorities between 2011 and 2019
{
"E06000028": "E06000058",
"E06000029": "E06000058",
"E07000048": "E06000058",
"E07000049": "E06000059",
"E07000050": "E06000059",
"E07000051": "E06000059",
"E07000052": "E06000059",
"E07000053": "E06000059",
"E07000190": "E07000246",
@drkane
drkane / faststreamer.py
Last active January 22, 2020 00:28
Fast streamer for BCP files
import argparse
import csv
def faststream(fp, blocksize=65536, line_delimiter='*@@*', field_delimiter='@**@'):
"""Read a BCP file and yield the rows
fp is a file pointer to a BCP file opened in 'r' mode.
It is assumed the file is opened with the correct encoding, so that·
fp.read() gives strings. A trailing newline may need to be added after this·
@drkane
drkane / 01_basic_queries.sql
Last active June 9, 2021 09:39
Queries that could be run on the 360Giving data store
-- required fields from 360Giving standard
-- http://standard.threesixtygiving.org/en/latest/reference/#grants-sheet
with g as (select * from view_latest_grant)
select g.data->>'id' as "id",
g.data->>'title' as "title",
g.data->>'description' as "description",
g.data->>'currency' as "currency",
(g.data->>'amountAwarded')::float as "amountAwarded",
to_date(g.data->>'awardDate', 'YYYY-MM-DD') as "awardDate",
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@drkane
drkane / normalise_string.py
Created August 29, 2018 14:00
normalise a pandas series string (built for the names of charities/other organisations)
# takes a pandas series
def normalize_string(s):
s = s.astype(str)
s = s.str.lower()
# replace apostrophes
def replace_apos(match):
return match.group(0).replace("'", "")
s = s.str.replace(r'\'s\b', replace_apos)
@drkane
drkane / kingston-lsoa.geojson
Last active June 11, 2018 08:35
Lower Super Output Area boundaries for Royal Borough of Kingston Upon Thames. Contains National Statistics data © Crown copyright and database right 2018 Contains OS data © Crown copyright and database right 2018 From ONS geoportal: http://geoportal.statistics.gov.uk/datasets/lower-layer-super-output-areas-december-2011-full-clipped-boundaries-…
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@drkane
drkane / kingston-wards.geojson
Last active June 10, 2018 23:03
Ward boundaries for Royal Borough of Kingston Upon Thames. From ONS geoportal: http://geoportal.statistics.gov.uk/datasets/wards-december-2017-full-clipped-boundaries-in-great-britain Contains National Statistics data © Crown copyright and database right 2018 Contains OS data © Crown copyright and database right 2018
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
We can't make this file beautiful and searchable because it's too large.
EmployerName,Address,CompanyNumber,SicCodes,DiffMeanHourlyPercent,DiffMedianHourlyPercent,DiffMeanBonusPercent,DiffMedianBonusPercent,MaleBonusPercent,FemaleBonusPercent,MaleLowerQuartile,FemaleLowerQuartile,MaleLowerMiddleQuartile,FemaleLowerMiddleQuartile,MaleUpperMiddleQuartile,FemaleUpperMiddleQuartile,MaleTopQuartile,FemaleTopQuartile,CompanyLinkToGPGInfo,ResponsiblePerson,EmployerSize,CurrentName,CharityNumber,CharityIncome,OrgType,OrgSubType,PaidMore,FemaleWorkforce
"""Bryanston School"",Incorporated","Bryanston House, Blandford, Dorset, United Kingdom, DT11 0PX",00226143,85310,18.0,28.2,0.0,0.0,0.0,0.0,24.4,75.6,50.8,49.2,49.2,50.8,51.5,48.5,https://www.bryanston.co.uk/employment,Nick McRobb (Bursar and Clerk to the Governors),500 to 999,"""Bryanston School"",Incorporated",306210,23130767.0,Charity,,Men,56.025
"""RED BAND"" CHEMICAL COMPANY, LIMITED","19, Smith's Place, Leith Walk, Edinburgh, EH6 8NU",SC016876,47730,2.3,-2.7,15.0,37.5,15.6,66.7,20.3,79.7,25.4,74.6,10.3,89.7,18.1,81.9,,Philip Galt (Man
@drkane
drkane / charity-reregistrations.csv
Created February 9, 2018 15:02
Charities registered in England and Wales that are the result of re-registration of an older charity
Old charity number New charity number
306072 1115974
Type Entity Company Number OSCAR CPID
Academy Trust Gateway Learning Community 05853746 CAD022
Academy Trust John Henry Newman Catholic College, The 07414011 CAD022
Academy Trust Abbey Multi Academy Trust 07705552 CAD022
Academy Trust Abbey School (Faversham), The 07697086 CAD022
Academy Trust St. Thomas More High School 07696989 CAD022
Academy Trust Peaslake Free School Limited 07925067 CAD022
Academy Trust Peatmoor Community Primary School 08714452 CAD022
Academy Trust Abney Trust 09912859 CAD022
Academy Trust Fulwell Infant School Academy 08277622 CAD022