Question

Are there Python or perhaps pandas equivalents to R's zoo package?

In particular, I'm looking for equivalents to:

dataLag2 = lag(zoo(train$data), -2, na.pad=TRUE)
train$dataLag2 = coredata(dataLag2)

Are there equivalents on Python that would produce the same results (the empty entry for zoo functionality in the Pandas documentation is a bit ominous).

Was it helpful?

Solution

Pandas has the TimeSeries class which implements all the functionalities available in zoo to manipulate and homogenize irregular time series data:

if 'ts' is a TimeSeries object containing irregular hourly timestamped data I'd first create an homogeneous time series doing:

ts.resample('H').interpolate()

And after, to create a lagged timeseries I'd use the shift() method. For example, to lag the previous timeseries 12 hours backwards:

ts.shift(-12)

http://pandas.pydata.org/pandas-docs/stable/timeseries.html

http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.shift.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top