使用Python中的Socrata client.get从Soda数据库查询

时间:2017-04-11 16:06:04

标签: python socrata soda

我正在尝试从数据库查询,我试图查找格式化SoQL字符串的正确方法,但我失败了。我尝试以下方法:

from __future__ import division, print_function
from sodapy import Socrata
import pandas as pd
import numpy as np


client = Socrata("data.cityofchicago.org", None)

df = client.get("kkgn-a2j4", query="WHERE traffic > -1")

并收到错误Could not parse SoQL query "WHERE traffic > -1" at line 1 character 1。但是,如果我执行以下操作,则可以:

from __future__ import division, print_function
from sodapy import Socrata
import pandas as pd
import numpy as np


client = Socrata("data.cityofchicago.org", None)

df = client.get("kkgn-a2j4", where="traffic > -1")

但我想知道如何使查询参数起作用,这样我就可以使用更复杂的查询。具体来说,我想尝试查询traffic > -1BETWEEN '2013-01-19T23:50:32.000' AND '2014-12-14T23:50:32.000'的时间。

1 个答案:

答案 0 :(得分:1)

您可以使用sodapy where参数(SoQl中的$where)来组合多个过滤器,只需使用AND来组合它们:

traffic > -1 AND last_update BETWEEN '2013-01-19T23:50:32.000' AND '2014-12-14T23:50:32.000'