I am using Juypter notebooks to look at some stock data. That being said, I have come across a weird error which I don't totally understand.
time_and_sales['Trade_time'] = time_and_sales['Trade_time'].astype(str)
start, stop, step = 0, -7, 1
time_and_sales['Trade_time'] = time_and_sales['Trade_time'].str.slice(start, stop, step)
time_and_sales['Trade_time'] = pd.to_datetime(time_and_sales['Trade_time'], format='%H:%M:%S')
print(type(time_and_sales['Trade_time']))
print(time_and_sales['Trade_time'].head(10))
Here is the code and here is the error
ValueError: time data '' does not match format '%H:%M:%S' (match)
Any help would be appreciated!
coerce or ignore
inpd.to_datetime
errors='coerce'
, that will leaveNaT
for inconvertible strings. You can then drop those rows withdropna()
.