我正在尝试使用Pandasql查询我的数据帧。然而,它给了我一个空的数据帧,尽管我知道它不应该这样做。我想这是因为我在where子句中错误地使用了今天的日期。以下是我代码的一部分:
df_event2import=[]
today = now.strftime("%Y-%m-%d")
q = """ select e.Date, e.SITA, e.Events from df_event e where e.Date >= date('today') """
df_event2import=((pandasql.sqldf(q, locals())))
df_all_event2import=df_all_event2import.append(df_event2import,ignore_index=True)
print(df_all_event2import)
下面是一些示例数据。这是在where子句中使用date('now')而不是date('today')后得到的结果。正如你所看到的,它给了我一月份以后的数据,这不是我想要的,我想要从今天开始的数据。在
^{pr2}$
除了@user2993886's answer,
2018/01/19
不是SQLite中的有效日期。The formats are documented,请参阅“时间字符串”。在您可以使用}。最好用
replace(e.Date, '/', '-')
将2018/01/19
转换为{update
永久地这样做,并在插入时使用正确的格式。使用本机日期格式将更快(查询可以被索引),并避免将来出现此类错误。在您应该使用
date('now')
,而不是使用date('today')
有关SQLite文档的更多详细信息:
https://www.sqlite.org/lang_datefunc.html
相关问题 更多 >
编程相关推荐