Giter Club home page Giter Club logo

sba-loans-covid-19-datasette's Introduction

sba-loans-covid-19-datasette

Notes on how I created https://sba-loans-covid-19.datasettes.com/

Twitter thread: https://twitter.com/simonw/status/1280283053726691329

Interesting queries:

Data source

I'm using the 150k plus/foia_150k_plus.csv file from the zip archive released here: https://sba.app.box.com/s/wz72fqag1nd99kj3t9xlq49deoop6gzf

Accompanying press release: https://home.treasury.gov/news/press-releases/sm1052

More downloads (e.g. per-state): https://home.treasury.gov/policy-issues/cares-act/assistance-for-small-businesses/sba-paycheck-protection-program-loan-level-data

Converting to SQLite

I used csvs-to-sqlite to convert the file to SQLite and make it searchable like this:

csvs-to-sqlite PPP\ Data\ 150k\ plus.csv \
    -t foia_150k_plus \
    loans_150k_plus.db \
    -c LoanRange \
    -c City \
    -c State \
    -c BusinessType \
    -c RaceEthnicity \
    -c Gender \
    -c Veteran \
    -c NonProfit \
    -d DateApproved \
    -c Lender \
    -c CD \
    -f BusinessName \
    -f Address

I added indexes to all of the foreign keys and optimized the database like this:

sqlite-utils index-foreign-keys loans_150k_plus.db
sqlite-utils optimize loans_150k_plus.db

Adding NAICS codes

The NAICSCode column contains six digit NAICS codes, which correspond to different industries.

I downloaded the "6-digit 2017 Code File" XLS file from https://www.census.gov/eos/www/naics/downloadables/downloadables.html and opened it in Numbers, then exported the data back out again as a two column CSV: naics_2017.csv

Then I ran the following commands - using sqlite-utils - to import that data and set it up as a foreign key from the NAICSCode column.

# First create the table with an integer primary key and a text column
sqlite-utils create-table loans_150k_plus.db naics_2017 id integer name text --pk=id
# Now import the data into it
sqlite-utils insert loans_150k_plus.db naics_2017 naics_2017.csv --csv
# Configure the foreign key
sqlite-utils add-foreign-key loans_150k_plus.db foia_150k_plus NAICSCode naics_2017 id
# Add an index to that column
sqlite-utils create-index loans_150k_plus.db foia_150k_plus NAICSCode

Publishing to Cloud Run

I published the database by running the following command:

datasette publish cloudrun \
    loans_150k_plus.db \
    --service sba-loans \
    --memory 2Gi \
    --extra-options "--config facet_time_limit_ms:2000" \
    --install datasette-block-robots \
    -m metadata.yml

sba-loans-covid-19-datasette's People

Contributors

simonw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sba-loans-covid-19-datasette's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.