I have a large data set with many columns. I am making each column an array. The first column is time in $H:$M:$S
00:00:00
00:00:01
00:00:02
...
23:59:58
23:59:59
When I put this into an array, it makes an object array. I use this to convert it to datetime:
time1=np.array2string(time)
dt.datetime.strptime(time1, "%H:%M:%S")
However, I keep getting an error:
ValueError: time data "[b'00:00:00' b'00:01:00' b'00:02:00' ... b'23:57:00' b'23:58:00'\n b'23:59:00']" does not match format '%H:%M:%S'
When I look at the actual array, it indeed does have that phantom 'b', but there is no 'b' in my dataset. It generates it out of thin air. What is causing this?
UPDATE:
I tried
time1=np.array2string(time)
time_strings = [dt.datetime.strptime(t, "%H:%M:%S") for t in time1]
and received the error:
ValueError: time data '[' does not match format '%H:%M:%S'
Not sure why a bracket is in there. It still appears to be making a 'b'.
strptimetakes a string as first positional argument, not the string representation of a whole array (which is what you tried to do). could use list comp instead:time_strings = [dt.datetime.strptime(t, "%H:%M:%S") for t in time]bindicates binary strings. maybe your data is encoded as binary?np.array2string- it will be hard to makedatetime.datetime.strptimework with that I guess