Skip to content

Instantly share code, notes, and snippets.

Becky Sweger bsweger

View GitHub Profile
View mock_requests.py
import pytest
import requests
@pytest.fixture
def mock_request_json():
"""Return fake API data."""
return {'spring': [
{
'name': 'birds',
'status': 'chirpin',
View gist:24a47e4c253dc9b17869ef096700dffd
### Keybase proof
I hereby claim:
* I am bsweger on github.
* I am bendystraw (https://keybase.io/bendystraw) on keybase.
* I have a public key ASCmomBSZgzxe3w1YQf-eZwTB3KNg7k4VGD29NN8hhmrDAo
To claim this, I am signing this object:
@bsweger
bsweger / seti_grants.py
Created Mar 9, 2018
USASpending API Snippets
View seti_grants.py
# Get SETI Institute grants from USAspending API into a pandas dataframe
import json
import requests
import pandas as pd
from pandas.io.json import json_normalize
uri = 'https://api.usaspending.gov/api/v2/search/spending_by_transaction/'
headers = {'content-type': 'application/json'}
seti_json = []
next = 1
@bsweger
bsweger / iterm_profile.json
Created Dec 12, 2017
Profiles and Dotfiles
View iterm_profile.json
{
"Ansi 3 Color" : {
"Green Component" : 0.73333334922790527,
"Blue Component" : 0,
"Red Component" : 0.73333334922790527
},
"Tags" : [
],
"Ansi 12 Color" : {
@bsweger
bsweger / financial_balances_agency.md
Last active Jun 7, 2017
financial_balances_agency.md
View financial_balances_agency.md

Retrieve financial balances by agency and fiscal year

Route: /api/v2/financial_balances/agencies

Method: GET

This route retrieves financial balance information by funding agency and fiscal year

Sample Request

/api/v2/financial_balances/agencies?funding_agency=775&fiscal_year=2017

@bsweger
bsweger / pandas_pad_using_apply.py
Created Jul 13, 2016
Apply a padding function to .csv columns (Pandas)
View pandas_pad_using_apply.py
# example of using a parameterized function as a converter when reading .csv in pandas
import pandas as pd
# a function that will be used to pad datafram column values to a specified length
# (some incoming values are multiple spaces; those should convert to Noe)
padFunction = lambda field, padTo: str(field).strip().zfill(padTo) if len(str(field).strip()) else None
# read file w/o using converters and display list of unique alloc_id values
pa = pd.read_csv(
@bsweger
bsweger / markdown-table-to-html.py
Last active Nov 26, 2019
Convert markdown table rows to html (we converted some markdown tables to html so we could use the "scope" attribute in the header rows for accessibility).
View markdown-table-to-html.py
#tabedata.txt is a file that contains the piped markdown table rows
with open ('markdownrows.txt') as f:
content = f.readlines()
rows = []
for c in content:
cells = c.split('|')
cells = ['<td>{}</td>'.format(cell.strip()) for cell in cells]
rows.append(cells)
View Taxes Paid and Personal Income.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View useful_pandas_snippets.md

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)

@bsweger
bsweger / Vagrantfile
Created Dec 17, 2012
Vagrantfile to set up a Python virtual environment for data analysis
View Vagrantfile
Vagrant::Config.run do |config|
config.vm.define :pythondata do |pythondata_config|
# Every Vagrant virtual environment requires a box to build off of.
pythondata_config.vm.box = "precise64"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
pythondata_config.vm.box_url = "http://files.vagrantup.com/precise64.box"
# Forward a port from the guest to the host, which allows for outside
You can’t perform that action at this time.