是否有 Python 或 pandas
等同于 R 的 zoo
包?
特别是,我正在寻找等同于:
dataLag2 = lag(zoo(train$data), -2, na.pad=TRUE)
train$dataLag2 = coredata(dataLag2)
Python 上是否有产生相同结果的等效项(empty entry for zoo
functionality in the Pandas documentation 有点不祥)。
最佳答案
Pandas 具有 TimeSeries 类,它实现了 zoo 中所有可用的功能来操作和均质化不规则的时间序列数据:
如果“ts”是一个包含不规则每小时时间戳数据的 TimeSeries 对象,我会首先创建一个同类时间序列:
ts.resample('H').interpolate()
之后,要创建滞后时间序列,我会使用 shift() 方法。例如,将之前的时间序列向后延迟 12 小时:
ts.shift(-12)
http://pandas.pydata.org/pandas-docs/stable/timeseries.html
http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.shift.html
关于R 的 'zoo' 包的 Python 等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22439929/