Skip to content

Instantly share code, notes, and snippets.

View gjreda's full-sized avatar

Greg Reda gjreda

View GitHub Profile
@gjreda
gjreda / concurrent_futures_example.py
Created September 25, 2016 21:14
example of using Python3's concurrent.futures module
from concurrent.futures import ProcessPoolExecutor
import concurrent.futures
from halas.parsers import boxscore
GAMES = [ ... ]
results = []
with ProcessPoolExecutor(max_workers=4) as executor:
future_results = {executor.submit(boxscore, game):
@gjreda
gjreda / pandas-groupby-cumulative-count-with-reset.py
Last active August 2, 2016 14:51
days since last login -- pandas groupby cumulative count with reset
# for creating a column like "days since last login"
df = pd.read_clipboard(index_col=['customer_id', 'days'])
(df
.groupby(level='customer_id')
.did_login
.cumsum()
.to_frame()
.groupby(level='customer_id')
.apply(lambda g: g.groupby('did_login').cumcount())
@gjreda
gjreda / gist:8611946
Created January 25, 2014 04:37
Weird numpy/pandas groupby behavior when using min() on a np.datetime64 field.
# OSX 10.7.5
# python 2.7.5
# pandas 0.13.0
# numpy 1.8.0
import pandas as pd
import numpy as np
from StringIO import StringIO
d = """row1,'2013-10-01'