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
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 | |
--------- |
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
########################################### | |
# 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): |
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
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 | |
} |
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
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', |
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
# 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 |
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
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) |
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
""" | |
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 |
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
""" | |
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() |
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
states_abbrev_dict = { | |
'AK': 'Alaska', | |
'AL': 'Alabama', | |
'AR': 'Arkansas', | |
'AS': 'American Samoa', | |
'AZ': 'Arizona', | |
'CA': 'California', | |
'CO': 'Colorado', | |
'CT': 'Connecticut', | |
'DC': 'District of Columbia', |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.