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
# To find out exactly which Python version you're using, you can use the --version flag | |
python --version | |
# Python 3 is usually available under the name python3 | |
# python3 --version | |
# You can also figure out the version with the runtime configuration | |
# import sys | |
# print(sys.version_info) | |
# print(sys.version) |
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
"""Get geolocation information from a zipcode. | |
https://pypi.python.org/pypi/zipcode | |
""" | |
import zipcode | |
def location_from_zipcode(zip=None): | |
return zipcode.isequal(zip).location_text |
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 requests | |
from bs4 import BeautifulSoup | |
from time import sleep | |
from multiprocessing import Pool | |
def get_listing(url): | |
headers = { | |
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'} | |
html = None |
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
"""You can either use the response.raw file object, or iterate over the response. | |
To use the response.raw file-like object will not, by default, decode compressed responses (with GZIP or deflate). | |
You can force it to decompress for you anyway by setting the decode_content attribute to True | |
(requests sets it to False to control decoding itself). You can then use shutil.copyfileobj() | |
to have Python stream the data to a file object: | |
""" | |
import requests | |
import shutil |
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 requests | |
response = requests.get('https://website.com/id', headers={'Authorization': 'access_token myToken'}) |
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 dask.dataframe as dd | |
import blaze | |
df = dd.read_csv('csv/yellow_tripdata_2015-*.csv') # '*' all files with the 'csv/yellow_tripdata_2015' prefix | |
df.to_parquet('yellow_tripdata.parquet') |
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 itertools | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from sklearn import svm, datasets | |
from sklearn.model_selection import train_test_split | |
from sklearn.metrics import confusion_matrix | |
# import some data to play with | |
iris = datasets.load_iris() |
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 sklearn.metrics import confusion_matrix | |
def print_cm(cm, labels, hide_zeroes=False, hide_diagonal=False, hide_threshold=None): | |
"""pretty print for confusion matrixes""" | |
columnwidth = max([len(x) for x in labels]+[5]) # 5 is value length | |
empty_cell = " " * columnwidth | |
# Print header | |
print " " + empty_cell, | |
for label in labels: | |
print "%{0}s".format(columnwidth) % label, |
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
def plot_tree(): | |
"""Make sure you have the correct imports. | |
Imports: | |
from sklearn import tree | |
import pydotplus | |
from IPython.display import Image | |
Note: Make sure you already have a 'tree'. | |
... | |
clf = tree.DecisionTreeClassifier() |
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
# --------------------------------------------------------------------------- | |
# | |
# Description: This file holds all my BASH configurations and aliases | |
# | |
# Sections: | |
# 1. Environment Configuration | |
# 2. Make Terminal Better (remapping defaults and adding functionality) | |
# 3. File and Folder Management | |
# 4. Searching | |
# 5. Process Management |
NewerOlder