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()
有帮助吗?

解决方案 2

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

其他提示

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'
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top