I have also tried
import os from pathlib import Path import pandas as pd import datetime def convert_file(): # Set start directory same as script os.chdir(os.path.abspath(os.path.dirname(__file__))) infile = Path('.') / 'gauga20211_19790101-20120101.txt' outfile = Path('.') / 'newfile.csv' with infile.open() as fp, outfile.open('w') as fout: startdate = None starttime = None nexttime = 0 for line in fp: line = line.strip().split() # extract header if line[0] == '1': startdate = pd.to_datetime(line[1], format='%Y%m%d') starttime = pd.to_datetime(line[2], format='%H%M') nexttime = starttime else: for item in line: data = f"{startdate}-{starttime},{item}\n" fout.write(data) nexttime += datetime.timedelta(minutes=2) if __name__ == '__main__': convert_file()The date format is however not as i try to format it, and the desired deltatime is not added
Output:1979-01-11 00:00:00-1900-01-01 10:07:00,3.333
1979-01-11 00:00:00-1900-01-01 10:07:00,3.333
1979-01-11 00:00:00-1900-01-01 10:07:00,3.333
1979-01-11 00:00:00-1900-01-01 10:07:00,0.556
1979-01-11 00:00:00-1900-01-01 10:07:00,0.556
1979-01-11 00:00:00-1900-01-01 10:07:00,0.556
1979-01-11 00:00:00-1900-01-01 10:07:00,0.556
1979-01-11 00:00:00-1900-01-01 10:07:00,0.556
1979-01-11 00:00:00-1900-01-01 10:07:00,0.556
1979-01-11 00:00:00-1900-01-01 10:07:00,3.333
1979-01-11 00:00:00-1900-01-01 10:07:00,0.370
1979-01-11 00:00:00-1900-01-01 10:07:00,0.370
1979-01-11 00:00:00-1900-01-01 10:07:00,0.370
Attached Files
gauga20211_19790101-20120101.txt (Size: 198.98 KB / Downloads: 90)