【发布时间】:2019-01-08 09:54:25
【问题描述】:
我正在尝试通过将数据帧切片传递给我的函数来对加速度计数据进行带通滤波器,但根据切片数据的方式,我得到了不同的结果
我尝试使用iloc 使用列名和索引,但结果不同,所以我不知道哪个结果是正确的结果
我的带通滤波器功能:
def butter_bandpass(lowcut, highcut, fs, order=6):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
b, a = butter(order, [low, high], btype='band')
return b, a
def butter_bandpass_filter(data, lowcut, highcut, fs):
b, a = butter_bandpass(lowcut, highcut, fs, order=6)
y = lfilter(b, a, data)
return y
以下两种方式,我曾经将数据传递给函数:
第一种方法:使用tremor_0[['X']] as [[]] 切片作为列名
y=pd.DataFrame(data=butter_bandpass_filter(tremor_0[['X']],0.3,12,100),columns=['X'])
第二种方式:
使用tremor_0['X'] as [] 切片作为列名
y=pd.DataFrame(data=butter_bandpass_filter(tremor_0['X'],0.3,12,100),columns=['X'])
第一种方式的结果:
X
0 -0.001962
1 -0.001962
2 -0.001948
3 -0.001903
4 -0.001874
第二种方式的结果:
X
0 -0.001962
1 -0.019822
2 -0.095867
3 -0.298136
4 -0.675933
请注意,从第二行开始,值是不同的,那么哪种方式是正确的方式,为什么?
【问题讨论】:
-
欢迎来到 SO。请提供minimal example to produce the error。请记住,社区成员是志愿者,需要一些时间(和努力才能理解)或不完整的问题会阻止人们回答。
标签: python python-3.x pandas python-2.7