[Python] putting API results into a dataframe in Python

Discussão em 'Python' iniciado por Stack, Julho 31, 2025.

  1. Stack

    Stack Membro Participativo

    i need some help. have got a part of a python script which accesses a url field in a sql database, and then calls an api based using the url in the field. Now i cannot get the data into a dataframe to then flatten and output to csv, can anyone help. The code so far is below

    import pyodbc
    import pandas as pd
    import requests as re
    from pathlib import Path
    import json
    import os

    server = 'TestServer'
    database = 'TestDB'
    cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER='+server+';DATABASE='+database+';Trusted_Connection=yes')
    cursor = cnxn.cursor()


    # select rows from SQL table to insert in dataframe.
    websites = "select TOP 2 URL FROM [dbo].[API_URL_TEST];"
    UUID_df = pd.read_sql(websites, cnxn)
    print(UUID_df.head(10))
    #print(df)

    from urllib.request import urlopen

    for link in UUID_df['URL']:
    with urlopen(link) as response:
    myfile = response.read()
    print(myfile)

    Continue reading...

Compartilhe esta Página