Skip to content

Instantly share code, notes, and snippets.

View a-y-khan's full-sized avatar

Ayla Khan a-y-khan

  • Salt Lake City, UT, USA
View GitHub Profile
@a-y-khan
a-y-khan / import.cypher
Created November 10, 2016 02:45
Cypher commands for importing data from CSV with null.
// Create subcontract info
// handling null fields from http://stackoverflow.com/questions/37081842/cant-merge-with-null-values-cannot-merge-node-using-null-property-value-in-n
USING PERIODIC COMMIT 100
LOAD CSV WITH HEADERS FROM "file:///subaward3.csv" AS row
MERGE (p:Primary {name: row.prime_awardee_parent_contractor_name, awardeeParentContractorName: row.prime_awardee_parent_contractor_name})
ON CREATE SET p.awardeeParentDUNS = row.prime_awardee_parent_duns
ON MATCH SET p.awardeeParentDUNS = row.prime_awardee_parent_duns
ON CREATE SET p.awardPrincipalNAICSCode = row.prime_award_principal_naics_code
ON MATCH SET p.awardPrincipalNAICSCode = row.prime_award_principal_naics_code
MERGE (s:Subaward {name: row.subawardee_name, DUNS: row.subawardee_dunsnumber, amount: row.subaward_amount})
@a-y-khan
a-y-khan / json_to_csv_flatter.py
Last active June 21, 2017 21:18
Extract properties from JSON file and write to CSV
import math
import sys
import ijson
import csv
import argparse
def extract_to_csv(json_filename, new_json_filename, csv_filename):
# ijson's parser chokes on NaNs, so let's get rid of them
# NaN containing fields not needed for Adam's analysis?
# if Circularity and Pixel area are NaN, we're in trouble!!!
@a-y-khan
a-y-khan / csv_importer.py
Created December 14, 2017 07:22
Convert Movie dataset CSV files to Pandas DataFrames
import argparse
import ast
import pandas as pd
from datetime import datetime
from distutils.util import strtobool
from typing import Dict, List, Union
def convert_to_dict_list(string: str) -> Union[List[Dict], None]:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@a-y-khan
a-y-khan / type_aliases.ipynb
Created February 16, 2018 06:07
Python type alias example
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@a-y-khan
a-y-khan / query_github_graphql.py
Last active February 21, 2018 06:02
TeamCity Python build step to query GitHub GraphQL endpoint
import json
import requests
import subprocess
def query_github_graphql(url: str, api_token: str, owner: str, service: str, pull_request: int):
headers = {'Authorization': 'bearer {}'.format(api_token), 'Content-Type': 'application/json'}
payload = {'query': '{repository(owner:\"%s\", name: \"%s\"){pullRequest(number: %d){headRefName,baseRefName}}}' % (owner, service, pull_request)}
response = requests.post(url=url, json=payload, headers=headers)
print(response.text)
@a-y-khan
a-y-khan / df_basics_1.ipynb
Created April 2, 2018 06:57
Pandas DataFrame axis basics (Part 1)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@a-y-khan
a-y-khan / df_basics_2.ipynb
Last active April 13, 2018 07:08
Pandas DataFrame axis basics (Part 2)
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.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.