Skip to content

Instantly share code, notes, and snippets.

View jseabold's full-sized avatar

Skipper Seabold jseabold

View GitHub Profile
@jseabold
jseabold / anova_lm.py
Created March 30, 2012 02:14
ANOVA fitted linear model comparison for statsmodels
from pandas import DataFrame
import numpy as np
from scipy import stats
def anova_lm(*args, **kwargs):
"""
ANOVA table for one or more fitted linear models.
Parmeters
---------
@jseabold
jseabold / cut.py
Created April 4, 2012 00:55
cut function for numpy
###########################################
# Note: this requires PR # 245 in numpy
# https://github.com/numpy/numpy/pull/245
#
# Author: Skipper Seabold
# License: BSD
import numpy as np
def cut(x, bins, right=True):
@jseabold
jseabold / rmpy.sh
Last active October 6, 2015 11:48
rmpy delete python packages from dist-packages
function rmpy {
if [ -z "$1" ]; then
echo "Aren't you glad I didn't delete everything?";
else
sudo rm -rf /usr/local/lib/python2.7/dist-packages/$1*
fi
}
@jseabold
jseabold / ipython_config.py
Last active October 9, 2015 05:07
ipython default profile config with git branch
c = get_config()
# lines of code to run at IPython startup.
c.TerminalIPythonApp.exec_lines = [
'Exit = exit',
'import numpy as np',
'np.set_printoptions(suppress=True)',
'import statsmodels.api as sm',
'import matplotlib.pyplot as plt',
'from scipy import stats, optimize',
@jseabold
jseabold / download_remote_dir.py
Created September 18, 2012 18:49
walk and download a remote http file server
# if you can, just use wget
# wget -np -r remote_url
import re
import os
import urllib2
import urlparse
import pycurl
from lxml import html
@jseabold
jseabold / gist:3757398
Created September 20, 2012 18:01
Perron-Frobenius theorem
T = np.array([[0,1,0],[0, .1, .9],[.6, .4, 0]])
p = np.array([.5, .2, .3])
ps = [np.inf, p]
while np.all(np.abs(ps[-1] - ps[-2]) > 1e-8):
ps.append(np.dot(ps[-1], T))
from scipy import linalg
# get the spectrum
eigs, evecs = linalg.eig(T, left=True, right=False)
@jseabold
jseabold / octal_to_unicode.py
Created September 25, 2012 19:12
octal to unicode and beyond the infinite
"""
I received a file that had octal characters as ascii. Needed to map them to latin-1 unicode and be able to go back again to latin-1 octal.
Might not be completely general, but it works for me.
E.g.,
name = 'Duchy of Zweibr\\374cken'
octalchar_to_unicode(name)
unicode_to_octalchar(octalchar_to_unicode(name))
http://www.utoronto.ca/web/HTMLdocs/NewHTML/iso_table.html
@jseabold
jseabold / get_poll_data.py
Created October 2, 2012 21:13
Download presidential poll data into a DataFrame
"""
Download all the Presidential Poll Data from Real Clear Politics and
put it in a DataFrame then put a bird on it.
Usage:
data2012_state_recent = download_latest_state_polls()
data2004, data2008, data2012 = download_national_polls()
data2012_state = download_state_polls()
@jseabold
jseabold / state_abbrevs.py
Created October 18, 2012 15:24
State abbreviation-names dictionary to use with loadpy
states_abbrev_dict = {
'AK': 'Alaska',
'AL': 'Alabama',
'AR': 'Arkansas',
'AS': 'American Samoa',
'AZ': 'Arizona',
'CA': 'California',
'CO': 'Colorado',
'CT': 'Connecticut',
'DC': 'District of Columbia',
@jseabold
jseabold / example_regression_plots.ipynb
Created October 31, 2012 14:41
Regression Diagnostics - Plotting
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.