Python Socrata API-无法处理浮动时间戳记

问题描述 投票:0回答:1

我是python编程的新手,所以为可能的新手问题表示歉意。我正在尝试在Marin County Socrata API中过滤“浮动时间戳记数据类型”。我正在使用他们在此处提供的基本轮廓:https://dev.socrata.com/foundry/data.marincounty.org/mkbn-caye#!/ usr / bin / env python

# make sure to install these packages before running:
# pip install pandas
# pip install sodapy

import pandas as pd
from sodapy import Socrata

# Unauthenticated client only works with public data sets. Note 'None'
# in place of application token, and no username or password:
client = Socrata("data.marincounty.org", None)

# Example authenticated client (needed for non-public datasets):
# client = Socrata(data.marincounty.org,
#                  MyAppToken,
#                  userame="[email protected]",
#                  password="AFakePassword")

# First 2000 results, returned as JSON from API / converted to Python list of
# dictionaries by sodapy.
results = client.get("mkbn-caye", limit=2000)

# Convert to pandas DataFrame
results_df = pd.DataFrame.from_records(results)

我正在尝试对数据库进行ping操作,以获取有关在上周内提交的许可申请(具有“ received_date”)但尚未颁发许可(没有“ issued_date”)的信息。我想每周运行代码以获取更新。

我开始使用下面的代码,它确实起作用:将熊猫作为pd导入从苏打水进口苏格拉底客户端= Socrata(“ data.marincounty.org”,MyAppToken)结果= client.get(“ mkbn-caye”,Received_date ='2019-09-25T13:50:27.000')results_df = pd.DataFrame.from_records(结果)print(results_df)#打印数据框

但是,如果我从“ =”运算符到“>”运算符做了一点改动:

results = client.get("mkbn-caye", received_date > '2019-09-25T13:50:27.000')

我得到以下错误代码:

results = client.get("mkbn-caye", received_date > '2019-09-25T13:50:27.000')

NameError:名称'received_date'未定义

'received_date'与“ =”运算符配合使用时,如何定义它呢?

就像我之前提到的,最终,我希望在接下来的工作中有所收获,但要迈出小步子

received_date > 'One Week Ago'\    #The date would be 1 week ago
issued_date IS NULL                # This doesn't work either. I want entries that have no "issued_date" field yet

我正在尝试在此处使用准则:https://dev.socrata.com/foundry/data.marincounty.org/mkbn-caye与“浮动时间戳记数据类型”一起使用。有什么建议么?

python-3.x api time socrata
1个回答
0
投票

这很简单。只是需要另外一对“”。

results = client.get("mkbn-caye", \
                 where="received_date > '2019-09-25T13:50:27.000'")
© www.soinside.com 2019 - 2024. All rights reserved.