[英]Python - How do I create a sliding window of columns in a text file?
I have text files from sensor data such as accelerometers and gyroscopes such as: 我有来自传感器数据的文本文件,例如加速度计和陀螺仪,例如:
% 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
with much more in the files. 文件中还有更多。
I want to create a sliding window of size 50 for each column of accelerometer axes because the sampling frequency is 100Hz. 我想为加速度计轴的每一列创建一个大小为50的滑动窗口,因为采样频率为100Hz。 I can print out each line of the first column like this: 我可以像这样打印出第一列的每一行:
def sliding_window(filename, stepSize, windowSize):
with open(filename) as infile:
for line in infile:
print(line.split()[0])
However, I shouldn't be printing out the first 17 lines as they are just comments in the text file. 但是,我不应该打印出前17行,因为它们只是文本文件中的注释。 How would I go about making this sliding window? 我将如何制作此滑动窗口?
Add a startswith
condition: 添加一个startswith
条件:
if not line.startswith('%'):
print(line.split()[0])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.