0
Hello, I am a Python beginner.
I am working with a txt file in Python. The file contains a time series for a given variable. Currently, my time variable is reported in the form of a range (1:100). I would like to replace such integers with the actual dates.
What I would need to do is via a loop as follows:
- Read the initial .txt file
- Replace the date range (1:100) in the ‘time’ column with the actual dates (01-01-2010 - …) and save the output as a new .txt file.
So far, I have tried this:
with open('F://tg.txt','r') as infile:
with open('F://tg2.txt','w') as outfile:
rdr = csv.reader(infile, delimiter=' ')
wtr = csv.writer(outfile, delimiter=' ')
header = next(rdr)
wtr.writerow(header)
for row in rdr:
pd.to_datetime(range(1, 100), origin="1950-01-01", unit="D", utc=True)
wtr.writerow(row)
The loop manages to create both an input and ouput file. However, the code I am using for ‘datetime’ does not change the integers to the actual date I want. Is there a way to solve this issue in Python? Thanks!