熊猫 0.14.1 中的重采样和插值时间序列



目标 我有两个时间序列数据框,df_templatethis_df 。两者都处于不同的采样率。我想使用插值重新采样this_dfdf_template

问题:我有以下代码在熊猫 0.19 中有效,但在熊猫 0.14.1 中不起作用。我如何让它工作?

df_template = pd.DataFrame()
this_df = pd.DataFrame()
t1 = np.arange(1484664735415, 1484664735710, 30)
t2 = np.arange(1484664735400, 1484664735700, 100)
df_template['Time'] = t1
this_df['Time'] = t2
this_df['S2'] = random.sample(xrange(50), this_df.shape[0])
this_df.set_index('Time', inplace=True)
this_idx = this_df.index.union(df_template.Time)
df_new = this_df.reindex(this_idx).interpolate('index').reindex(df_template.Time)
df_new.reset_index(inplace=True)

错误发生在 this_df.index.union() 中。

AttributeError: 'Series' object has no attribute 'is_monotonic'

我认为熊猫 0.14.1 中没有这样的功能。那么,我如何获得最终结果,例如:

            Time     S2
0  1484664735415  22.25
1  1484664735445  26.75
2  1484664735475  31.25
3  1484664735505  33.95
4  1484664735535  27.65
5  1484664735565  21.35
6  1484664735595  15.05
7  1484664735625  14.00
8  1484664735655  14.00
9  1484664735685  14.00

有什么想法可以在熊猫 0.14.1 中工作吗?

使用外部连接使其正常工作

this_idx = pd.concat([df_template, this_df], axis = 1, join = 'outer').index
df_new = this_df.reindex(this_idx).interpolate('index').reindex(df_template.index)

最新更新