根据 url 列表 [pandas] 创建合并 df

Create merged df based on the url list [pandas]

我能够从 url_query url 中提取数据,但另外,我想从基于 query['ids'] 创建的 urls_list 中获取数据来自数据框的列。请看下面的当前逻辑:

    url = 'https://instancename.some-platform.com/api/now/table/data?display_value=true&'
    team = 'query=group_name=123456789'
    url_query = url+team

    dataframe: query
         [ids]
    0    aaabbb1cccdddeee4ffggghhhhh5iijj
    1    aa1bbb2cccdddeee5ffggghhhhh6iijj

    issue_list = []
    for issue in query['ids']:
        issue_list.append(f'https://instancename.some-platform.com/api/now/table/data?display_value=true&?display_value=true&query=group_name&sys_id={issue}')

    response = requests.get(url_query, headers=headers,auth=auth, proxies=proxies)

data = response.json()

def api_response(k):
   dct = dict(
   event_id= k['number'],
   created_time = k[‘created’],
   status = k[‘status’],
   created_by = k[‘raised_by’],
   short_desc = k[‘short_description’],
   group = k[‘team’]
    )
    return dct

raw_data = []
for p in data['result']:
    rec = api_response(k)
    raw_data.append(rec)

df = pd.DataFrame.from_records(raw_data)

df:

url_query 响应提取了我需要的内容,但关键是我想添加到现有的 'df' 添加来自 issue_list = [] 的数据。我不知道如何将 issue_list = [] 放入响应中。我试图将 issue_list 添加到 response = requests.get(issue_list, headers=headers,auth=auth, proxies=proxies) 语句,但我遇到了无效架构错误。

您可以使用查询 q 而不是 url_query 创建数据帧列表,最后通过 concat:

连接在一起
dfs = []
for issue in query['ids']:
    q = f'https://instancename.some-platform.com/api/now/table/data?display_value=true&?display_value=true&query=group_name&sys_id={issue}'

    response = requests.get(q, headers=headers,auth=auth, proxies=proxies)

    data = response.json()
    raw_data = [api_response(k) for p in data['result']]
    df = pd.DataFrame.from_records(raw_data)
    dfs.append(df)
    
df = pd.concat(dfs, ignore_index=True)