【发布时间】:2026-02-22 04:25:01
【问题描述】:
我编写了一个循环来根据 id 列表从 API (Limesurvey) 检索数据,并用每个循环的结果填充数据帧的一行。
我有一个这样的 id 列表:
# list of ids
ids = ['1','427',... ,'847']
我根据列表中的每一项查询 API 的代码如下所示:
method = "get_participant_properties"
params = OrderedDict([
("sSessionKey", api.session_key),
("iSurveyID", 12345),
("aTokenQueryProperties", t),
])
# loop through API query with the 'aTokenQueryProperties' stored in the list 'tids'.
attributes = []
for t in ids:
attributes.append(api.query(method=method, params=params))
pd.DataFrame(attributes)
不幸的是,结果是一个158行的dataframe,每一行都是一样的,即我列表中最后一个id的查询结果(847)。
【问题讨论】:
标签: json python-3.x api for-loop limesurvey