Skip to content

Instantly share code, notes, and snippets.

def readfile(filename):
with open(filename) as f:
df = pd.read_html(f)[0]
df.columns = ['date', 'views']
df['date'] = df['date'].apply(lambda x:dateutil.parser.parse(x))
df = df.set_index('date')
df['day_of_week'] = df.index.map(lambda t:t.dayofweek)
df['max_weekly_value'] = df.views-pd.rolling_max(df.views, 7)==0
return df
weekdays = ['Mondays', 'Tuesdays', 'Wednesdays', 'Thursdays', 'Fridays', 'Saturdays', 'Sundays']
#observed data
popsize = 10000.0
infected_data = np.array([ 7, 10, 11, 11, 13, 14, 14, 13, 14, 16, 18, 18, 20, 21, 22, 23, 23, 24, 25, 23])
T = len(infected_data)
I0 = 7
R0 = 5
# priors
@rouli
rouli / gist:9407500
Last active August 29, 2015 13:57
My brother's python homework
import csv
titanic = open('titanic.txt', "rb")
reader = csv.reader(titanic)
prefix_list = ["Mr ", "Mrs", "Mis"] # used to determine if passanger's name includes a prefix. Using 3 chars because of Mr.
# There are several demographic details we can count passengers and survivors by, this is a dictionary to map them out along with col number in the file.
@rouli
rouli / harwriter.py
Created April 28, 2013 10:44
A script to create a HAR file out of a mitmproxy's dump file
#!/usr/bin/env python
import binascii, sys, json
import version, tnetstring, flow
from datetime import datetime
def create_har(flows):
return {
"log":{