Labelling data set with year, month,date and times

19 Views Asked by At

I have few data as follows:

0.907752

0.916137

0.923206

0.919096

0.928631

........

0.922548

and I want to do is to insert year ,month, date and time in the data as follows:

2012-12-01 00:00:00 0.907753

2012-12-01 00:00:01 0.907752

2012-12-01 00:00:02 0.923206

2012-12-01 00:00:03 0.919096

2012-12-01 00:00:04 0.928631

2012-12-01 00:00:05 0.930111

2012-12-01 00:00:06 0.931261

............................

............................

2012-12-01 23:59:58 0.585707

2012-12-01 23:59:59 0.923206

A novice in python.

1

There are 1 best solutions below

0
Andrei Gurko On

I don'n know what is a dateformat of 0.90777 but steel, this soluttion may help you:

  1. build your list of your date (timestamp)
  2. go thrue the list and conterting to datetime from timestamp and format this object
  3. print result string
import datetime


dates = [0.907752, 0.916137, 0.923206]
for date in dates:
    print(f"{datetime.datetime.fromtimestamp(0.922548).strftime('%y-%m-%d %H:%M:%S')} {date}")