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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
a = numpy.array([0, 3, 0, 1, 0, 1, 2, 1, 0, 0, 0, 0, 1, 3, 4]) | |
unique, counts = numpy.unique(a, return_counts=True) | |
dict(zip(unique, counts)) # returns {0: 7, 1: 4, 2: 1, 3: 2, 4: 1} |
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 pandas as pd | |
import requests | |
from io import BytesIO | |
# using a 538 dataset as an example | |
url = 'https://raw.githubusercontent.com/fivethirtyeight/data/master/bob-ross/elements-by-episode.csv' | |
response = requests.get(url) | |
content = BytesIO(response.content) | |
df = pd.read_csv(content) |
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
# multiwindow | |
"C:\Program Files\VcXsrv\vcxsrv.exe" :0 -ac -terminate -lesspointer -multiwindow -clipboard -wgl -dpi auto |
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 https://stackoverflow.com/a/44444489/7471215 | |
# puts commas in integers | |
ax.set_yticklabels(['{:,}'.format(int(x)) for x in ax.get_yticks().tolist()]) | |
# formats percentages | |
ax.set_yticklabels(['{:.0%}'.format(x) for x in ax.get_yticks().tolist()]) |
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 check_nulls(df): | |
df_cols = df.columns | |
col_counts = [df[col].count() for col in df_cols] | |
col_lens = [len(df[col]) for col in df_cols] | |
cdf = pd.DataFrame(index = df_cols, | |
data = {'Values':col_counts, | |
'Total': col_lens}) | |
cdf['% N/A'] = 1-(cdf['Values']/cdf.Total) | |
cdf['% N/A'] = cdf['% N/A'].map('{:.1%}'.format) # formats as percentages | |
return cdf |
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
match (n) | |
unwind labels(n) as s | |
return distinct s, count(s) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
""" | |
Data access utilities | |
""" | |
from collections.abc import Mapping | |
import os | |
import boto3 | |
import botocore.client | |
class Bucket(Mapping): |
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 pandas as pd | |
import boto3 | |
s3 = boto3.resource('s3') | |
data_file = s3.Object(bucket_name='challenge-1-data-09122019', key='data/wiki_movie_plots_deduped.csv') | |
resp = data_file.get() | |
data = pd.read_csv(resp['Body']) |
OlderNewer