Created
June 21, 2022 02:59
-
-
Save susanli2016/4d57ed991d7a1bf79b45082e3790e32c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fred_api_key = 'your API key' | |
def get_fred_series_data(api_key, series): | |
url = "https://api.stlouisfed.org/geofred/series/data?series_id={0}&api_key={1}&file_type=json".format(series, api_key) | |
response = requests.request("GET", url) | |
return response | |
def transform_series_response(response): | |
latest_date = list(response.json()['meta']['data'].keys())[0] | |
return pd.DataFrame(response.json()['meta']['data'][latest_date]) | |
response = get_fred_series_data(fred_api_key, series) | |
df_all_series_ids = transform_series_response(response) | |
df_all_series_ids.head() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment