【发布时间】:2017-09-01 21:12:50
【问题描述】:
我有一个数据系列:
df = pd.DataFrame({'Values': [-0.8765, -1, -1.2, 3, 4, 5, -12.0021, 10, 11, 12, -0.982]},
index = [pd.Timestamp('20130101 09:00:00'),
pd.Timestamp('20130101 09:00:02'),
pd.Timestamp('20130101 09:00:03'),
pd.Timestamp('20130101 09:00:05'),
pd.Timestamp('20130101 09:00:06'),
pd.Timestamp('20130101 09:00:07'),
pd.Timestamp('20130101 09:00:08'),
pd.Timestamp('20130101 09:00:09'),
pd.Timestamp('20130101 09:00:10'),
pd.Timestamp('20130101 09:00:11'),
pd.Timestamp('20130101 09:00:12')
])
所以,我必须在我的数据框中找到一个模式。 例如,我有这样的模式:
pattern = [4,5,-12.0021,10]
所以,现在我运行这个算法:
print(df.iloc[[int(df.index.get_indexer_for((df[df.Values==i].index))) for i in pattern]])
然后它回到我身边:
Values
2013-01-01 09:00:06 4.0000
2013-01-01 09:00:07 5.0000
2013-01-01 09:00:08 -12.0021
2013-01-01 09:00:09 10.0000
好的,很酷。
但我还需要在我的数据框中找到类似的模式。
所以,我有这个模式: 模式 = [4,5,-12.0021,10] 例如,如果我将这些值放入我的数据框中:[4,5,-12.01,10.1]。该算法不返回我,因为它只返回等于,但我也需要返回相似的。
我用了什么?
【问题讨论】:
-
是一个选项DTW吗?