我一直在尝试从下面的api流式传输数据,但收效甚微。在
https://dev.socrata.com/foundry/data.cityofchicago.org/8v9j-bter
在主.py脚本
#install main packages
!pip install sodapy
import pandas as pd
from sodapy import Socrata
from google.datalab import Context
#put into dataframe
client = Socrata("data.cityofchicago.org", None)
results = client.get("8v9j-bter", limit=2000)
results_df = pd.DataFrame.from_records(results)
#flow into BigQuery
results_df.to_gbq('chicago_traffic.demo_data', Context.default().project_id,
chunksize=2000, verbose=True, if_exists='append')
在应用程序yaml脚本
^{pr2}$在克罗恩·亚姆脚本
cron:
- description: "append traffic data"
url: /.*
target: main
schedule: every 1 mins
retry_parameters:
min_backoff_seconds: 2.5
max_doublings: 5
在要求.txt在
pandas==0.22.0
sodapy==1.4.6
datalab==1.1.2
google-api-python-client
和应用程序yaml您正在使用您将在App Engine Standard Enviroment中部署的。当您使用标准环境时,您可以通过将these built-in third party libraries添加到应用程序yaml或者您可以按照此link中的步骤使用任何其他第三方库。在
这里的问题是,正如previous link I shared中所述:
pandas库的部分代码是用C(https://pandas.pydata.org/#library-highlightsHow to solve import error for pandas?)编写的 ),因此,为了使用Pandas,您需要使用App Engine Flexible Environment。在
为了使部署运行,您需要对文件进行一些修改。按照以下链接调整文件以适应灵活的环境:
啊!pip安装sodapy使用魔法命令!,which is something exclusive from some Notebooks environments。不能将该行添加到主.py文件。此操作(pip install sodapy)将在应用程序部署期间运行,因为您正在将sodapy==1.4.6添加到要求.txt文件。在
而不是添加上下文.默认值().project_id,您应该能够将您的project_id添加为str。在App Engine内部运行时,Flex授权不应成为问题。如果要在本地运行它,请记住使用具有正确权限的a service account。在
相关问题 更多 >
编程相关推荐