This file contains hidden or 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
| { | |
| "metadata": { | |
| "name": "wiki_scrape" | |
| }, | |
| "nbformat": 3, | |
| "nbformat_minor": 0, | |
| "worksheets": [ | |
| { | |
| "cells": [ | |
| { |
This file contains hidden or 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 numpy as np | |
| import matplotlib.pyplot as plt | |
| #As a path collection | |
| from matplotlib.collections import LineCollection | |
| fig, ax = plt.subplots() | |
| r = np.arange(0, .075, 0.00001) | |
| nverts = len(r) |
This file contains hidden or 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
| /* hack to clear screen in stata */ | |
| program define cls | |
| di _newline(`=c(pagesize)') | |
| end |
This file contains hidden or 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 urllib | |
| import re | |
| def ungoogle(url, type="pdf"): | |
| try: | |
| return urllib.unquote(re.search("(?<=url=).+"+type, url).group()) | |
| except: | |
| return urllib.parse.unquote(re.search("(?<=url=).+"type, url).group()) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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', |
This file contains hidden or 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 hidden or 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 hidden or 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) |