我有一组在常规时间测量的值。你说:在熊猫中插入一个时间序列到另一个时间序列
import pandas as pd
import numpy as np
rng = pd.date_range('2013-01-01', periods=12, freq='H')
data = pd.Series(np.random.randn(len(rng)), index=rng)
,另一组的多个任意时间,例如,(在现实中这些时间是不是正规的顺序)
ts_rng = pd.date_range('2013-01-01 01:11:21', periods=7, freq='87Min')
ts = pd.Series(index=ts_rng)
我想知道在时间内插数据的值在ts。
我可以在numpy的做到这一点:
x = np.asarray(ts_rng,dtype=np.float64)
xp = np.asarray(data.index,dtype=np.float64)
fp = np.asarray(data)
ts[:] = np.interp(x,xp,fp)
但我感觉熊猫在resample
,reindex
等地方这个功能,但我不能完全得到它。
您需要使用方法=“值”的主要论点在插值得到同样的答案在numpy pd.concat([data,ts])。sort_index()。interpolate(method ='values')[ts.index] – elfnor
注意显示在ts和数据中的索引 – tschm