我有两个numpy数组light_points和time_points,希望对这些数据使用一些时间序列分析方法。
我试过这个:
import statsmodels.api as sm
import pandas as pd
tdf = pd.DataFrame({'time':time_points[:]})
rdf = pd.DataFrame({'light':light_points[:]})
rdf.index = pd.DatetimeIndex(freq='w',start=0,periods=len(rdf.light))
#rdf.index = pd.DatetimeIndex(tdf['time'])
这是可行的,但不是正确的做法。 事实上,测量值不是均匀的时间间隔,如果我将时间点pandas DataFrame声明为我的帧的索引,就会得到一个错误:
rdf.index = pd.DatetimeIndex(tdf['time'])
decomp = sm.tsa.seasonal_decompose(rdf)
elif freq is None:
raise ValueError("You must specify a freq or x must be a pandas object with a timeseries index")
ValueError: You must specify a freq or x must be a pandas object with a timeseries index
我不知道该怎么纠正。
而且,熊猫的TimeSeries
似乎也被弃用了。
我试过这个:
rdf = pd.Series({'light':light_points[:]})
rdf.index = pd.DatetimeIndex(tdf['time'])
但它给了我一个长度不匹配:
ValueError: Length mismatch: Expected axis has 1 elements, new values have 122 elements
不过,我不知道它是从哪里来的,因为rdf[“light”]和 tdf['time']的长度相同。。。
最后,我尝试将我的rdf定义为pandas系列:
rdf = pd.Series(light_points[:],index=pd.DatetimeIndex(time_points[:]))
我明白了:
ValueError: You must specify a freq or x must be a pandas object with a timeseries index
然后,我试着用
pd.TimeSeries(time_points[:])
它给了我一个关于季节分解法的错误:
AttributeError: 'Float64Index' object has no attribute 'inferred_freq'
如何处理间距不均的数据? 我正在考虑通过在现有值之间添加许多未知值并使用插值来“计算”这些点来创建一个近似等距的时间数组,但我认为可能会有一个更干净、更容易的解决方案。
seasonal_decompose()
需要一个freq
,它是作为DateTimeIndex
元信息的一部分提供的,可以由pandas.Index.inferred_freq
推断,或者由用户作为integer
提供每个周期的周期数。e、 例如,每月12次(从docstring
到seasonal_mean
):举例说明-使用随机样本数据:
到目前为止,很好-现在从
DateTimeIndex
中随机删除元素以创建不均匀的空间数据:在此数据上运行
seasonal_decomp
有效:问题是-结果有多有用。即使没有使季节模式推断复杂化的数据空白(参见release notes中
.interpolate()
的示例使用,statsmodels
也将此过程限定为:相关问题 更多 >
编程相关推荐