【问题标题】:Resampling and Interpolating Time Series in Pandas 0.14.1Pandas 0.14.1 中的重采样和插值时间序列
【发布时间】:2017-06-03 10:38:11
【问题描述】:

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

问题:我有以下codepandas 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 中使用吗?

【问题讨论】:

    标签: python pandas


    【解决方案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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-24
      • 2017-02-23
      • 1970-01-01
      • 2016-10-03
      • 2014-09-29
      • 2019-10-20
      • 2019-10-10
      • 2019-01-18
      相关资源
      最近更新 更多