2016-09-04 7 views
0

私はiPhoneデバイスから収集された加速度計データを持つフレームを持っています。 avgサンプリングレートは100Hzですが、私は補間されたすべてのデータ(x、y、z)で固定されたものを持っていたいと思います。それはパンダで可能ですか?たとえば、ここに私のDFの頭パンダの加速度計データを固定サンプリングレートに補間するにはどうすればよいですか?

されています:

ts   x   y   z 
0.006960 -0.075324 -0.175405 0.167105 
0.016970 -0.048325 -0.186265 0.180108 
0.026949 -0.017635 -0.158964 0.215963 
0.036959 -0.097063 -0.063350 0.256945 
0.046969 -0.139939 -0.046091 0.179085 
... 

TSがどのように見えるように、私は、それが100Hzの一定のサンプリング怒りを持っている必要がありますどのような: 0.00, 0.01, 0.02, 0.03 ... 0.99, 1.00, 1.01 ...

はありがとうあなたは事前に助けてくれます。 ts

答えて

1

おそらくこれを行うより効率的な方法がありますが、scipyを使用して各列を対象の時間配列に補間し、補間データから新しいデータフレームを作成することができます。

import numpy as np 
import pandas as pd 
from scipy import interpolate 

# define the time points of interest 
fs = 100 # sampling rate 
T = 1/fs # period 
ts = np.arange(0, 0.05, T) 

# create a dictionary of interpolated data 
interp_data = {} 

# loop through the columns and populate 
for key in ['x', 'y', 'z']: 
    # fit the univariate spline to the data 
    spl = interpolate.UnivariateSpline(df['ts'], df[key]) 
    # compute interpolated values on new time points 
    interp_data[key] = spl(ts) 

# convert to data frame 
interp_frame = pd.DataFrame(interp_data, index=ts) 
interp_frame.index.name = 'ts' 
interp_frame.head() 
2

インデックスあなたのデータフレームを:

index2 = pd.Index(pd.np.arange(0.00, 1.00, .01)) 

は、現在のインデックスとそれをマージし、追加の行を取得するためのデータフレームのインデックスを再作成:

df = df.reindex(df.index.union(index2)) 

df = df.set_index('ts') 

はあなたが必要なインデックスを作成します。

補間:

df.interpolate() 
関連する問題