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 pandas as pd | |
| def confusion_matrix(df: pd.DataFrame, col1: str, col2: str): | |
| """ | |
| Given a dataframe with at least | |
| two categorical columns, create a | |
| confusion matrix of the count of the columns | |
| cross-counts | |
| use like: |
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 pandas as pd | |
| def latex_two_column_table(title: str, l_caption: str, r_caption: str, l_df: pd.DataFrame, r_df: pd.DataFrame): | |
| """ | |
| Use to print out two-columned LaTeX code (or route into a file) for a set of dataframes | |
| """ | |
| l_df_tex = l_df.to_latex() | |
| r_df_tex = r_df.to_latex() | |
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 os | |
| import shutil | |
| def flatten_directory(directory, delete_after=False): | |
| """ | |
| Flattens all folders in directory, deleting the empty folders after. | |
| **WARNING** | |
| This code WILL DELETE YOUR FILES | |
| if used naively. Seriously. |
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 pandas as pd | |
| def get_word_counts(document: str) -> pd.DataFrame: | |
| """ | |
| Turns a document into a dataframe of word, counts | |
| Use preprocessing/lowercasing before this step for best results. | |
| If passing many documents, use document = '\n'.join(iterable_of_documents) |
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
| git clone https://[insert username]:[insert password]@github.com/[insert organisation name]/[insert repo name].git |
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 pickle | |
| import dill | |
| dill._dill._reverse_typemap['SliceType'] = slice | |
| dill._dill._reverse_typemap['ObjectType'] = object |
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 matplotlib.pyplot as plt | |
| params = {'legend.fontsize': 'x-large', | |
| 'figure.figsize': (15, 15), | |
| 'axes.labelsize': 'x-large', | |
| 'axes.titlesize': 'x-large', | |
| 'xtick.labelsize': 'x-large', | |
| 'ytick.labelsize': 'x-large'} | |
| plt.rcParams.update(params) |
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 json | |
| import pickle | |
| def openJSON(path): | |
| """ | |
| Safely opens json file at 'path' | |
| """ | |
| with open(path, 'r') as File: | |
| data = json.load(File) |
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 time | |
| def get_timestamp(): | |
| """ | |
| Print the date in m/d/y format, GMT | |
| >>> get_timestamp() | |
| '3_31_2020' | |
| """ | |
| t = time.gmtime() |
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 matplotlib.pyplot as plt | |
| import soundfile as sf | |
| from pydub import AudioSegment | |
| # we want to convert source, mp3, into dest, a .wav file | |
| source = "./recordings/test.mp3" | |
| dest = "./recordings/test.wav" | |
| # conversion - check! |
OlderNewer