1

我(似乎)成功地使用分页通过 Python API 调用遍历 Airtable 记录。但是我无法理解如何从第一次调用中附加数据并且所有迭代都得到调用。我的代码如下:

while offset is not None:
    next_url = url +'&offset='+ offset
    next_response = requests.get(next_url, params=params, headers=headers)
    output = next_response.json()
    for record in output["records"]:
       print(json.dumps(record))
    if "offset" in output:
        offset = output["offset"]
    else:
        offset = None 

        x = pd.DataFrame(output)
        x = x['records'].apply(pd.Series)
        x = x['fields'].apply(pd.Series)
        print(x)

        Series = {'offset': 'itrSuqdXIeBNUIR9R/rec0Nx6MPArR8mew8',
         'records': [{'createdTime': str,
                      'fields': {'*CHANNEL': str,
                                 '*START/LAUNCH/LOTS': str,
                                 '*STATUS': str,
                                 'CREATIVE OPS': str
                                 }
                                }]
                            }

然后我尝试创建附加数据集的数据框。我在循环中的哪个位置附加数据?

4

1 回答 1

2

我想到了:

while offset is not None:
next_url = url +'&offset='+ offset

next_response = requests.get(next_url, params=params, headers=headers)

output = next_response.json()

for record in output["records"]:
   print(json.dumps(record))
   all_pages.append(record)
if "offset" in output:
    offset = output["offset"]
else:
    offset = None 

    x = pd.DataFrame(all_pages)
    # x = x['records'].apply(pd.Series)
    x = x['fields'].apply(pd.Series)
    print(x)

我不再需要将记录属性应用于数据集。我只需要询问字段。现在,我在所有一个数据框中的指定字段的视图中都有所有记录!

于 2019-11-21T20:04:24.750 回答