Pergunta

from pandas.io import sql
import sqlalchemy

eng = sqlalchemy.create_engine('sqlite:////path/to/file.db')

In [20]: sql.execute("select * from mytable", eng).fetchone()
Out[20]: (0, u'2013-03-13 13:05:00.000000', 1, 0, 0, 0)

Now what should I do to get this to work:

target = Timestamp('2014-04-30')
sql.execute("select * from mytable where date = ?", eng, params=target).\
            fetchone()
Foi útil?

Solução 2

str_format = '%Y-%m-%d %H:%M:%s'
target = Timestamp('2014-04-30').strftime(str_format)

Outras dicas

Theres a typo in the answer, the last %s (lowercase) should be a %S (uppercase)

>>> str_format = '%Y-%m-%d %H:%M:%s'
>>> target = pd.Timestamp('2014-04-30').strftime(str_format)
>>> target
'2014-04-30 00:00:1398808800'  

>>> str_format = '%Y-%m-%d %H:%M:%S'
>>> target = pd.Timestamp('2014-04-30').strftime(str_format)
>>> target
'2014-04-30 00:00:00'
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top