Apr-25-2022, 07:07 PM
Hi everyone
As I posted a few weeks ago (https://python-forum.io/thread-36845-pos...#pid155721), I want extract parts of multiple log-files and put it in a dataframe.
For a single log-file the code looks like this:
As I posted a few weeks ago (https://python-forum.io/thread-36845-pos...#pid155721), I want extract parts of multiple log-files and put it in a dataframe.
For a single log-file the code looks like this:
import pandas as pd data = '/Users/roger/Data/Logs/train/2020-09-16_21-12-40_eventLog_enGB.txt' with open(data, "r") as file: items = [] for line in file: if ":" in line: a,b = map(str.strip, line.split(":", maxsplit=1)) items.append(b) new_result = items[0:4] df = pd.DataFrame([new_result], columns=['Model', 'S/N', 'timestamp', 'SW']) print(df)
Output: Model S/N timestamp SW
0 Hamilton-C1 25455 2020-09-16_21-12-40 2.2.9
How can I do this for multiple files in a folder? Each file should write in a additional line, like this:Output: Model S/N timestamp SW
0 Hamilton-C1 25455 2020-09-16_21-12-40 2.2.9
1 Hamilton-C1 25456 2020-09-17_21-12-42 2.2.9
Thanks for helping me!