Skip to content

Instantly share code, notes, and snippets.

data = []
for d in range(d):
temp = df.ix[:, ['event_id', 'obj_%d_id' % d, 'obj_%d_foo' % d, 'obj_%d_bar' % d]]
data.append(temp)
@dalejung
dalejung / converion.py
Created August 7, 2012 16:55
pandas <-> xts
# https://github.com/dalejung/trtools/blob/master/trtools/rpy/conversion.py
import sys, copy, os, itertools
import rpy2.robjects as robjects
import rpy2.rinterface as rinterface
from rpy2.robjects.vectors import SexpVector, ListVector
from rpy2.robjects.robject import RObjectMixin, RObject
import rpy2.robjects as robj
import numpy as np
import pandas.rpy.common as rcom
# If your data.frame index is unordered and you only have one column. This portion of xts will error.
if(!is.null(x) && !isOrdered(order.by, strictly=!unique) ) {
indx <- order(order.by)
if(NCOL(x) > 1 || is.matrix(x)) {
x <- x[indx,]
} else x <- x[indx]
order.by <- order.by[indx]
}
# Create a uniform date range.
times = format(as.POSIXct('2002-04-07', tz='GMT') + seq(1, by=1800, length.out=48))
rdf = data.frame(bob=1:48)
rownames(rdf) = times
as.xts(rdf)
# Error in `[.data.frame`(x, indx) : undefined columns selected
@dalejung
dalejung / binning and grouping.ipynb
Created August 13, 2012 20:57
Test nbviewer #notebook-project #inactive
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dalejung
dalejung / bob.py
Created August 14, 2012 04:51
Test #notebook #inactive
import pandas as pd
@dalejung
dalejung / gappy_charting.ipynb
Created August 15, 2012 03:58
Charting #notebook-project #inactive
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dalejung
dalejung / faber.ipynb
Created August 15, 2012 08:03
RPY and Quantstrat #notebook-project #inactive
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dalejung
dalejung / modifying series frames panels.ipynb
Created August 16, 2012 03:59
Pandas Stuff #notebook-project #inactive
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dalejung
dalejung / endpoints.R
Created August 16, 2012 22:37
End point for weeks
utc_time <- as.POSIXlt(c("2012-08-12 23:55:00","2012-08-13 00:05:00"), tz="UTC")
utc_weeks <- endpoints(utc_time, "weeks")
# [1] 0 1 2
est_time <- as.POSIXlt(c("2012-08-12 23:55:00","2012-08-13 00:05:00"), tz="US/Eastern")
est_weeks <- endpoints(est_time, "weeks")
# [1] 0 2