Apr-08-2022, 01:18 PM
(Apr-06-2022, 09:14 PM)deanhystad Wrote: There must be lines with more than one ":" in it. Maybe a time?
You can tell split when to stop splitting. This tells split to stop after the first split.
a, b = map(str.strip, line.split(":", maxsplit=1)) items.append([b])
Thank you, it is working now with the following code:
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] print(new_result)
Output:['Hamilton-C1', '25455', '2020-09-16_21-12-40', '2.2.9']
After the list, I put it in a dataframe:import pandas as pd df = pd.DataFrame([new_result], columns=['Model', 'S/N', 'timestamp', 'SW']) df
Output: Model S/N timestamp SW
0 Hamilton-C1 25455 2020-09-16_21-12-40 2.2.9
Now, I have a folder with thousends of log files and will get this information and put it also in a dataframe.How I can do this, as simple as possible?
Thanks for helping me again.