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

Querying from Soda database using Socrata client.get in Python

我正在尝试从数据库中进行查询,并且尝试查找格式化 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' 时尝试查询。

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

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