Interpolating one time series onto another in pandas

前端 未结 3 740
别那么骄傲
别那么骄傲 2021-02-09 16:24

I have one set of values measured at regular times. Say:

import pandas as pd
import numpy as np
rng = pd.date_range(\'2013-01-01\', periods=12, freq=\'H\')
data          


        
3条回答
  •  -上瘾入骨i
    2021-02-09 17:07

    You can concatenate the two time series and sort by index. Since the values in the second series are NaN you can interpolate and the just select out the values that represent the points from the second series:

     pd.concat([data, ts]).sort_index().interpolate().reindex(ts.index)
    

    or

     pd.concat([data, ts]).sort_index().interpolate()[ts.index]
    

提交回复
热议问题