【发布时间】:2017-06-03 10:38:11
【问题描述】:
目标 我有两个时间序列数据框,df_template 和 this_df。两者都处于不同的采样率。我想使用插值将this_df 重新采样为df_template。
问题:我有以下code 在pandas 0.19 中有效,但在pandas 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'
我认为 pandas 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
有什么想法可以在 pandas 0.14.1 中使用吗?
【问题讨论】: