python - 在python中对齐三个时间序列

标签 python pandas time-series

我有以下时间序列: enter image description here

我想仅在时间 = 800 之后对齐信号,基于对齐最小点。

我尝试了以下方法来对齐 pandas 中的两个信号:

from pandas import *
import pandas as pd
s1 = Series(vec1)
s2 = Series(vec2)
s3 = s1.align(s2,join='inner')

s1 = np.array(s1)
s2 = np.array(s2)
s3 = np.array(s3)

plt.plot(t,s1)
plt.plot(t,s2)
plt.plot(t,s3)
plt.show()

它显示了与原始形式完全一致的对齐信号。关于如何实现最小对齐有什么建议吗?

最佳答案

找到并对齐最小值:

import matplotlib.pyplot as plt  #making toy data
x = np.arange(0, 2, .05)

s = []
s.append(np.sin(x*3))
s.append(np.cos(x*4+0.3))
s.append(np.sin(x)*np.exp(2-x)*-1)
plt.clf()
plt.plot(x, s[0], x, s[1], x, s[2])
plt.show()
plt.clf()

enter image description here

mindexes = [i.argmin() for i in s]  #finding the minima
shifts = mindexes - min(mindexes)

def shifted(shift, x, s):
    if shift == 0:   #x[:-0] was not what I wanted.
        return x, s
    else:
        return x[:-1*shift], s[shift:]

for i in (0,1,2):
    px, py = shifted(shifts[i], x, s[i]) 
    plt.plot(px, py)
plt.show()

enter image description here

关于python - 在python中对齐三个时间序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29367747/

相关文章:

python - reshape pandas 数据框失败

pandas - 在python2.7-alpine中的Docker中安装 Pandas 时,Docker构建失败

python - 通过值比较动态选择数据框字段

python - 在 Django 的模板中显示来自模型的个人资料图片

java - 手机无法连接到同一 wifi 网络上的 Flask 服务器

sql - Postgres 中的时间序列

r - 将 xts 转换为 ts : Error in Round(frequency)

python - 如何获得FB Prophet的特征重要性?

python - 在 Python 中对二进制文件列表执行按位运算的优雅方法是什么?

python - 不可散列类型 : 'Dimension' in Keras LSTM