...
q='SELECT EXTRACT(HOUR FROM dTime) as hour FROM data'
output=pandasql.sqldf(q,globals())
(column dTime contains time-data as e.g. '2019-02-15 03:44:27')
It doesn't work due to this error:
OperationalError: near "FROM": syntax error
I'm not able to understand how to solve it, could you help me?
SQLite does not support the function
extract()
, but you can usestrftime()
:this returns the hour as a string in the format
hh
.If you want the hour as a number, then:
By adding
0
to the result ofstrftime()
it is implicitly converted to a number.