Skip to content

Instantly share code, notes, and snippets.

@ReidWilliams
ReidWilliams / pandas.txt
Last active February 22, 2018 14:47
Pandas cheatsheet
# rename a dataframe column
dataframe = dataframe.rename(index=str, columns={'old_col_name': 'new_col_name'})
# get all possible values for a string / categorical column
dataframe[column].value_counts(dropna=False)
# group data and count number of rows in a group
grouped = dataframe.groupby(color)
nreds = len(grouped.get_group('red'))
@ReidWilliams
ReidWilliams / freeze-install.txt
Created January 30, 2018 21:39
Python: freeze and install packages
$ pip freeze > requirements.txt
$ pip install -r requirements.txt
@ReidWilliams
ReidWilliams / anaconda.txt
Created December 15, 2017 01:10
Anaconda cheatsheet
# create environment with jupyter
conda create -n ENVNAME python=3 jupyter
@ReidWilliams
ReidWilliams / ssh.sh
Created December 5, 2017 00:05
SSH with port forwarding
# Easy way to remotely access a Jupyter notebook, by forwarding a port
# Forward local port 8888 to the remote's localhost port 8888
ssh -L 8888:localhost:8888 user@10.2.2.99
@ReidWilliams
ReidWilliams / rsync.sh
Last active November 2, 2017 02:48
rsync a repo
while true; do rsync -e "ssh -i /PATH/TO/PRIVATE/KEY.pem" -azvh --delete ./LOCAL-REPO/ ec2-user@IP:/REMOTE/PATH; sleep 2; done
@ReidWilliams
ReidWilliams / killnode.sh
Last active January 27, 2017 00:08
One line command to kill node debug processes on Mac OS
kill -9 $(ps -ef | grep '[n]ode --debug-brk=5858' | awk '{print $2}')
@ReidWilliams
ReidWilliams / inspect.js
Created July 13, 2015 00:48
Inspect functions that are part of a promise chain
// Uses underscore.js to wrap a function and upon calling
// prints the function source and the argument.
// Useful for debugging chains of promises.
// USAGE
// var myfunction = function(argument) {...};
// myfunction = inspect(myfunction); // myfunction is now instrumented
var _ = require('underscore');
var util = require('util');
var inspect = function(fnToInspect) {