0

I want to scrape data at the county level from https://apidocs.covidactnow.org

However I could only get a dataframe with one line for each county, and data for each date is stored within a dictionary in each row/county. I would like to access this data and store it in long format (= have one row per county-date).

import requests
import pandas as pd
import os


if __name__ == '__main__':
    os.chdir('/home/username/Desktop/')

    url = 'https://api.covidactnow.org/v2/counties.timeseries.json?apiKey=ENTER_YOUR_KEY'
    response = requests.get(url).json()
    
    data = pd.DataFrame(response)

This seems like a trivial question, but I've tried for hours. What would be the best way to achieve that ?

1 Answer 1

0

Do you mean something like that?

import requests

url = 'https://api.covidactnow.org/v2/states.timeseries.csv?apiKey=YOURAPIKEY'

response = requests.get(url)
csv_response = (response.text)

# Then you can transform STRING to CSV

Check this fo string to CSV --> python parsing string to csv format

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.