str_format = '%Y-%m-%d %H:%M:%s'
target = Timestamp('2014-04-30').strftime(str_format)
format pandas.Timestamp for SQLite query
سؤال
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
نصائح أخرى
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'
لا تنتمي إلى StackOverflow