This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Utility function to help with local prototyping to minimize trips to fetch data. | |
# Import the function and decorate any data-retrieval function to use cache if | |
# available, make one if not. Remove the decorator before submitting to production. | |
import cPickle as pickle | |
import logging | |
import os | |
from functools import wraps | |
THIS_DIR = os.getcwd() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import os | |
import re | |
def main(sql_file): | |
with open(sql_file, 'r') as f: | |
sql = f.read() | |
sql = sql.upper().replace('WITH', ',') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source: http://matplotlib.org/examples/pylab_examples/demo_tight_layout.html | |
# define initially | |
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex='col', sharey='row') | |
# MATLAB numbering | |
fig = plt.figure() | |
ax1 = plt.subplot(221) | |
ax2 = plt.subplot(222) | |
ax3 = plt.subplot(223) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://pandas.pydata.org/pandas-docs/stable/cookbook.html/ bottom example | |
def expand_grid(data_dict): | |
rows = itertools.product(*data_dict.values()) | |
return pd.DataFrame.from_records(rows, columns=data_dict.keys()) | |
df = expand_grid( | |
{'height': [60, 70], | |
'weight': [100, 140, 180], | |
'sex': ['Male', 'Female']}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user = raw_input('Enter BGG username') | |
url = 'http://www.boardgamegeek.com/xmlapi2/collection?username=' | |
import requests | |
import time | |
# return collection for any user, but wait 2 seconds and retry if error. 10 total attempts. | |
def coll_final(USER): | |
for i in range(10): # try 10 times | |
r = requests.get(url + USER + "&rated=1&excludesubtype=boardgameexpansion&stats=1") |