Skip to content

Instantly share code, notes, and snippets.

@benjaminmgross
benjaminmgross / list_numpy_compare.py
Last active August 29, 2015 13:58
Differences between Numpy & List Comprehensions
def gen_tickers(num_tickers, num_new):
"""
This function generates `num_tickers` of random, length 3 tickers and
`num_new` random, length 3 tickers
"""
s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
r = numpy.random.randint(1, 27, 3)
ticks = []
#create the list of tickers
for i in numpy.arange(num_tickers):
@benjaminmgross
benjaminmgross / ff_fudgery.json
Last active August 29, 2015 14:01
Fama French Fudgery
{
"metadata": {
"name": "",
"signature": "sha256:12e3c9503b4648f28853f643f8c87ee662a50293d691268338736c4f49e808f0"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@benjaminmgross
benjaminmgross / README.md
Created June 1, 2014 08:12
Exploding Bar Chart

#Why

I haven't seen any visualizations of "Exploding Bar Charts" using matplotlib like the this one:

exploding_bar

So I put together some very quick code to show how it could be done

#WIP

@benjaminmgross
benjaminmgross / shexxshy_dicts.md
Last active August 29, 2015 14:02
Makin' a Shexy `dict`

#Motivation

I was getting fed up with the usual, list of keys, looping through, and assigning a value to the key... I wanted something a little shexxier using Python's map functionality.

Here's what I came up with

##Makin' a Sexy Dict

#Parsing API xml data using BeautifulSoup

I had a difficult time extracting data from a xml object retrieved using the requests. Simply, I had dome something like:

[In] 1: import requests
[In] 2: socket = requests.get('https://the?xml?shitting&api?url')

Most of the documents I found pointed me towards 'xml' and using ElementTree. After several attempts, with no success at all, I was able to get the desired result by using BeautifulSoup. Specifically the following:

##Step 1:

@benjaminmgross
benjaminmgross / main.md
Created August 18, 2014 02:45
Getting A `(key, value) dict` from your Categorical Variables

#Intro

If you're dealing with categorical variables, it's highly valuable to have:

  1. Number representations for the category (so you can do things like sklearn algorithms)
  2. A dictionary mapping of the numbers to the categories (for groupby and other such methods)

I couldn't find something built-in, but the solve is pretty easy (and sexy), and a on-liner

@benjaminmgross
benjaminmgross / main.md
Last active August 29, 2015 14:05
Using the Billion Prices Project to Get Daily Inflation Data

##Turning The Billion Prices Data Series into Actual Inflation Data

They keep the data in tough to reach nooks... but I gotcha..

data_url = 'https://globalmarkets.statestreet.com/Proxy/Public/csv/US_monthly_series.csv'
bpp = pandas.DataFrame.from_csv(data_url)

#data is "monthly" and in points, but needs to be converted into daily
apr = bpp/100.*12
# `conda` env vars
## Quick `gist` to setup `conda` env variables
I try to keep `virtualenv` and `conda` going to ensure I stay versed in both virtual environment
methodologies. In `virtualenv` I can simply moding the script located in `$PATH/bin/activate` where
`$PATH` is the path to the virtual environment I'm working on. However, the process in `conda` is a
little more involved (but also straightforward, as all things `conda` seem to be).
## Create `activate / deactivate` directories
@benjaminmgross
benjaminmgross / conda_env_vars.md
Created August 11, 2015 15:56
`conda` env variables

conda env vars

Quick gist to setup conda env variables

I try to keep virtualenv and conda going to ensure I stay versed in both virtual environment methodologies. In virtualenv I can simply moding the script located in $PATH/bin/activate where $PATH is the path to the virtual environment I'm working on. However, the process in conda is a little more involved (but also straightforward, as all things conda seem to be).

Create activate / deactivate directories

@benjaminmgross
benjaminmgross / screen_commands.md
Created December 18, 2018 14:18
Commands I Can't Remember
# create a new screen called sumpTin & nutTin
$ screen -S sumpTin
$ screen -S nutTin

# Exit sumpTin in detached state
# Ctrl A, Ctrl D

# list existing screens
$ screen -ls