Mar-08-2020, 12:19 AM
Hi, I am trying to convert a time date string into a time serial of 0 to 1 designating the hour of the day. I could not find anything existing to use and so tried to write a function and map it.
TSLA_1Sec is an array with the column 'Local TimeBid' being a series of strings:
11.02.2020 01:30:07.000 GMT+1100
11.02.2020 01:30:08.000 GMT+1100
11.02.2020 01:30:10.000 GMT+1100
11.02.2020 01:30:11.000 GMT+1100
11.02.2020 01:30:12.000 GMT+1100
11.02.2020 01:30:14.000 GMT+1100
My coding:
I tried to change 'Local TimeBID' series from a dtype object to string, thinking this was the problem with no success.
TSLA_1Sec is an array with the column 'Local TimeBid' being a series of strings:
11.02.2020 01:30:07.000 GMT+1100
11.02.2020 01:30:08.000 GMT+1100
11.02.2020 01:30:10.000 GMT+1100
11.02.2020 01:30:11.000 GMT+1100
11.02.2020 01:30:12.000 GMT+1100
11.02.2020 01:30:14.000 GMT+1100
My coding:
#convert timedate column into a 0-1 designation of time. def TimeSerialFunc(DateStringStamp): DateStringStamp = DateStringStamp[11:-13] tHr = int(DateStringStamp[:2])/24 tMin = int(DateStringStamp[3:5])/24/60 tSec = int(DateStringStamp[6:])/24/60/60 return tHr + tMin + tSec TSLA_1sec['Local TimeBID'].astype('str') print(TSLA_1sec ['Local TimeBID'] ) TSLA_1sec ['Local TimeBID'] = map(TimeSerialFunc,TSLA_1sec['Local TimeBid']) print( TSLA_1sec['Local TimeBid'])My traceback error:
Quote:Exception has occurred: KeyError
'Local TimeBid'
File "/Users/jasonrae/Documents/Python Files/pandas/_libs/hashtable_class_helper.pxi", line 1626, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "/Users/jasonrae/Documents/Python Files/TSLA Try1.py", line 55, in <module>
TSLA_1sec ['Local TimeBID'] = map(TimeSerialFunc,TSLA_1sec['Local TimeBid'])
I tried to change 'Local TimeBID' series from a dtype object to string, thinking this was the problem with no success.