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 ?

asked Apr 30, 2021 at 15:18

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

answered Apr 30, 2021 at 15:34
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.