Skip to content

Instantly share code, notes, and snippets.

@elena-roff
elena-roff / custom_logger.py
Created September 14, 2018 09:34
Custom logger for both console printing (error level) and saving to a file
# example output
# __main__ - WARNING - This is a warning
# __main__ - ERROR - This is an error
import logging
# Create a custom logger
logger = logging.getLogger(__name__)
# Create handlers
@elena-roff
elena-roff / plot_by_groups.py
Created September 13, 2018 11:18
Plotting correlations using groups from groupby
grouped_df = data.groupby('col')
num_subplots = grouped_df.ngroups
fig_corr = plt.figure(figsize=(15, 250))
count = 0
for name, group in grouped_df:
# limit by n of observations in a group
if group.shape[0] >= 100:
count = count + 1
ax_corr = fig_corr.add_subplot(round(num_subplots/3) + 1, 3, count)
@elena-roff
elena-roff / decorator.py
Created August 28, 2018 09:03
Decorator template
# source: https://realpython.com/primer-on-python-decorators/
# This formula is a good boilerplate template for building more complex decorators.
import functools
def decorator(func):
@functools.wraps(func)
def wrapper_decorator(*args, **kwargs):
# Do something before
value = func(*args, **kwargs)
# Do something after
@elena-roff
elena-roff / regr_stats.py
Created August 22, 2018 15:10
Regression: performance statistics + plots
from sklearn.metrics import r2_score, mean_squared_error
import matplotlib.lines as mlines
import matplotlib.transforms as mtransforms
def stats(value, pred):
res = [
{
'metric': 'R2',
'value' : r2_score(value, pred)
}
@elena-roff
elena-roff / write_to_db.py
Created August 7, 2018 09:10
Write to MySQL DB from csv file
import pandas as pd
import mysql.connector.pooling
start_cred = {
'db_user': <db_user>,
...
}
cnx = mysql.connector.pooling.MySQLConnectionPool(**start_cred)
data = pd.read_csv('filename')
@elena-roff
elena-roff / vim-cheatsheet.md
Created July 30, 2018 12:11 — forked from azadkuh/vim-cheatsheet.md
vim / vimdiff cheatsheet - essential commands

Vim cheat sheet

Starting Vim

vim [file1] [file2] ...

@elena-roff
elena-roff / .gitconfig
Last active July 30, 2018 12:10 — forked from pksunkara/config
Sample of git config file (Example .gitconfig)
[user]
name = <name>
email = @gmail.com
username = <username>
[core]
editor = vim
whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
excludesfile = ~/.gitignore
[web]
browser = google-chrome
@elena-roff
elena-roff / bobp-python.md
Created July 30, 2018 12:07 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@elena-roff
elena-roff / tmux.md
Created July 30, 2018 12:06 — forked from andreyvit/tmux.md
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

@elena-roff
elena-roff / .vimrc
Last active July 30, 2018 11:59
Custom vim config
" Configuration file for vim
" To customize it, copy to ~/.vimrc and edit!
set nocompatible " Use Vim defaults (much better!)
set bs=2 " allow backspacing over everything in insert mode
set history=50 " keep 50 lines of command line history
set textwidth=0 " Don't wrap words by default
set ruler " Show the line and column numbers of the cursor