我有来自传感器数据的文本文件,例如加速度计和陀螺仪,如:
% Accelerometer data recorded with 'snsrlog'
%
% Sampling frequency: 100 Hz
%
% Label description:
% 0: Default Label
% 1: pick up phone
%
% Column description:
% 1: Seconds.milliseconds since 1970
% 2: Number of skipped measurements
% 3: Acceleration value in x-direction
% 4: Acceleration value in y-direction
% 5: Acceleration value in z-direction
% 6: Label used for the current sample
%
%
1495573445.162 0 0.021973 0.012283 -0.995468 1
1495573445.172 0 0.021072 0.013779 -0.994308 1
1495573445.182 0 0.020157 0.015717 -0.995575 1
1495573445.192 0 0.017883 0.012756 -0.993927 1
1495573445.202 0 0.021194 0.012161 -0.994705 1
1495573445.212 0 0.019638 0.013718 -0.994019 1
1495573445.222 0 0.019440 0.010803 -0.994476 1
文件中包含更多内容。
我想为每列加速度计轴创建一个大小为50的滑动窗口,因为采样频率为100Hz。我可以打印出第一列的每一行,如下所示:
def sliding_window(filename, stepSize, windowSize):
with open(filename) as infile:
for line in infile:
print(line.split()[0])
但是,我不应该打印前17行,因为它们只是文本文件中的注释。我该如何制作这个滑动窗口?
答案 0 :(得分:1)
添加startswith
条件:
if not line.startswith('%'):
print(line.split()[0])