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 datetime | |
# Filename function for logging | |
def dt_filename( | |
filename: str, | |
extension: str, | |
path: str = "", | |
date: str = str(datetime.datetime.now()), | |
) -> str: | |
filename = "_".join([filename, date]) |
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
def dataframe_difference(df1, df2, which=None): | |
"""Find rows which are different.""" | |
comparison_df = df1.merge(df2, | |
indicator=True, | |
how='outer') | |
if which is None: | |
diff_df = comparison_df[comparison_df['_merge'] != 'both'] | |
else: | |
diff_df = comparison_df[comparison_df['_merge'] == which] | |
diff_df.to_csv('data/diff.csv') |
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 | |
def plot_stacked_bar(data, series_labels, category_labels=None, | |
show_values=False, value_format="{}", y_label=None, | |
colors=None, grid=True, reverse=False): | |
"""Plots a stacked bar chart with the data and labels provided. | |
Keyword arguments: | |
data -- 2-dimensional numpy array or nested list |
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
## Split into holdout for purposes of imputation and encoding | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = .2, random_state=2019) | |
class_labels = df['segment_label'].cat.categories | |
## Preprocessing pipeline | |
# Define transforms on numeric types | |
numeric_features = X.select_dtypes(np.number).columns | |
numeric_transformer = Pipeline(steps=[ | |
('imputer', SimpleImputer(strategy='median')), |
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
from IPython.display import HTML | |
HTML('''<script> | |
code_show=true; | |
function code_toggle() { | |
if (code_show){ | |
$('div.input').hide(); | |
} else { | |
$('div.input').show(); | |
} |
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
#!/usr/bin/python | |
def merge(l): | |
# Base case | |
if len(l) < 2: | |
return l | |
mid = len(l) // 2 | |
y = merge(l[:mid]) |
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
x = [1,2,3] | |
def test(): | |
print("x-slice id before",id(x[:])) | |
print("x-slice before", x[:]) | |
x[:] += [4] | |
print("x-slice id after",id(x[:])) | |
print("x-slice after", x[:]) | |
print("x id", id(x)) |
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
def printMove(fr, to): | |
print('move from ' + str(fr) + ' to ' + str(to)) | |
def Towers(n, fr, to, spare): | |
if n == 1: | |
printMove(fr, to) | |
else: | |
Towers(n-1, fr, spare, to) | |
Towers(1, fr, to, spare) | |
Towers(n-1, spare, to, fr) |
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
#!/bin/python | |
import sys | |
n = int(raw_input().strip()) | |
s = raw_input().strip() | |
k = int(raw_input().strip()) | |
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
# Atom Beautify - Debugging information | |
The following debugging information was generated by `Atom Beautify` on `Fri Mar 03 2017 11:05:22 GMT-0800 (PST)`. | |
--- | |
## Table Of Contents | |
- [Versions](#versions) | |
- [Original file to be beautified](#original-file-to-be-beautified) | |
- [Original File Contents](#original-file-contents) |