python - numpy interpolation using pandas -


i trying interpolation pandas columns belonging different dataframes different sampling rates. stripped timestamp , used count value index. looked @ multiple ways interpolation on pandas , not come elegant solution. here's hack using np.interp method. there better method or alternative in pandas? in advance !

import numpy np import matplotlib.pyplot plt import pandas pd plt.style.use('seaborn-deep')  df1 = pd.dataframe({'s1':np.random.random(10)}) df2 = pd.dataframe({'s2':np.random.random(5)})  # interpolate df2 keeping first , last values , increase length of df2  len(df1) df1_index = np.arange(0,1,np.float(1/np.float(len(df1)))) df2_index = np.arange(0,1,np.float(1/np.float(len(df2)))) df2_on_df1 = np.interp(df1_index, df2_index, df2['s2']) print len(df1), len(df2), len(df2_on_df1) plt.plot(df2_on_df1) plt.hold # plt.plot(df1) plt.plot(df2) plt.legend(loc='upper right') plt.show() 

enter image description here


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -