【发布时间】:2019-04-11 14:38:11
【问题描述】:
我有一个 code 列,我想将其传递给 Web 服务并使用返回的 JSON 中的两个值(RbcSecurityDescription 和 RbcSecurityType1 ). 我已经通过迭代实现了这一点,但我想知道是否有更有效的方法来做到这一点?
# http://postgre01:5002/bond/912828XU9
import requests
url = 'http://postgre01:5002/bond/'
def fastquery(code):
response = requests.get(url + code)
return response.json()
这是示例返回调用:
这里是dfMRD1['Cache_Ticker']和dfMRD1['Cache_Product']的更新
dfMRD1 = df[['code']].drop_duplicates()
dfMRD1['Cache_Ticker'] = ""
dfMRD1['Cache_Product'] = ""
for index, row in dfMRD1.iterrows():
result = fastquery(row['code'])
row['Cache_Ticker'] = result['RbcSecurityDescription']
row['Cache_Product'] = result['RbcSecurityType1']
display(dfMRD1.head(5))
最好只返回 json 数组,取消它并将其内容中的所有字段转储到另一个我可以与 dfMRD1 加入的 df 吗?实现这一目标的最佳方法?
【问题讨论】: