I have 12 files all with the same format:
Statistics Information
Line: 4
Fiducial range: 156 to 364
Number of items: 209
Number of dummies: 0
Minimum value: -0.08983668870989447
Maximum value: 0.059795797205623558
Mean value: -0.00884060126461031
Standard deviation: 0.03707261357656038
Arithmetic sum: -1.8476856643035546
Each file is for a manoeuvre in a specific direction, North (Pitch, roll, Yaw), South (Pitch, roll, Yaw), East (Pitch, roll, Yaw) and West (Pitch, roll, Yaw).
I want to cycle through each of these text files and store the number for each minimum, maximum and mean value for each file. Then export them in a table:
| NORTH | Pitch | Roll | Yaw |
|---|---|---|---|
| Min | -0.08983668870989447 | ||
| Max | 0.059795797205623558 | ||
| Mean | -0.00884060126461031 |
| South | Pitch | Roll | Yaw |
|---|---|---|---|
| Min | |||
| Max | |||
| Mean |
et cetera
So far I have managed to list the different files and then extract the first line:
import glob
txt_files = glob.glob("*.txt")
def read_first_line(txt_files):
with open(txt_files, 'rt') as fd:
first_line = fd.readline()
return first_line
output_strings = map(read_first_line, txt_files) # apply read first line function all text files
print(txt_files)
output_content = "".join(sorted(output_strings))
output_content # as a string
print(output_content) # print as formatted
with open('outfile.txt', 'wt') as fd:
fd.write(output_content)