0

I have a piece of python code that is part of a bigger code that gets data using an API. I have created several for loops, but the heart of the for loop is:

    for page in offets:
        base_url = base_url + id + str(page)
        response = requests.get(base_url, auth=auth))
        output_from_api = response.json()
        raw_data.append(output_from_api)
        data = pd.DataFrame(output_from_api['elements'])
        dataframes_contact.append(data)

this works for multiple id's however its difficult to determine which dataset belongs to which id. I think the best way would be to add a column that appends the id to a column, however I have been unsuccessful.

I have tried this but does not work:

data.apply(id, axis=1)

this is the output I would like. the id column will be filled in as the for loop fills data. desired output

using Python 3.9, pandas==1.4.3

any help / suggestions will be really appreciated

1 Answer 1

1

Instead of using apply I think you should just set the id column like so:

data['id'] = id
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.