Reputation: 349
This data has no date time or other useful columns like other questions address.
I have a pandas data frame ( or single series) returned without date information like so :
[10:1]
0 2.264555
1 3.555655
2 4.023047
3 3.500272
4 3.033678
.. ...
152 3.808607
153 4.222035
154 5.205624
155 5.025041
156 5.711009
What I do have is the starting time and the time interval between each row.
Basically startingTime : 2020-02-19T02:54:29.000Z and timeInterval : "0.05" (5 seconds)
How could I go about creating an x,y style format like [[datetime, value], [datetime, value]] ?
Is this a situation where you would typically do the opposite of what i'm thinking and inject the computed date time as column in the data frame first?
Upvotes: 0
Views: 1162
Reputation: 13349
You can create timestamp like this:
from datetime import datetime, timedelta
date_list = [str(datetime(2010, 2, 19, 2, 54, 29).strftime('%Y-%m-%d %H:%M:%S Z')) + str(timedelta(seconds=5*x)) for x in range(0, len(df))]
Result:
['2010-02-19 02:54:29 Z0:00:00',
'2010-02-19 02:54:29 Z0:00:05',
'2010-02-19 02:54:29 Z0:00:10',
'2010-02-19 02:54:29 Z0:00:15',
'2010-02-19 02:54:29 Z0:00:20',
'2010-02-19 02:54:29 Z0:00:25',
.
.
.
]
then
df.insert(0, 'TimeStamp', date_list)
Upvotes: 1
Reputation: 319
Creating a datetime column with fixed time interval:
import datetime
starting_time = datetime.datetime(2020,2,19,2,54,29)
td = 5 # timedelta
df['datetime'] = [starting_time + datetime.timedelta(seconds=i*td) for i in range(len(df))]
Then you can apply this to convert your values into list:
list(zip(df['datetime'], df['Column']))
Upvotes: 1