This file contains hidden or 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
import pandas as pd | |
import requests | |
import json | |
from typing import List | |
def multiSeries( | |
varList: List[str], | |
myKey: str, | |
first:str ='2020', | |
last: str ='2025', |
This file contains hidden or 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
def readJSONfile(fname): | |
#first, check if fname is a string | |
if type(fname) == str: # the input is of type string | |
#second, check if a file of the name fname exists | |
if os.path.exists(fname): # a file of the name strored in fname exists | |
# we can now open the file | |
f = open(fname) # f is of type _io.TextIOWrapper |
This file contains hidden or 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
def extract_substring(text, start_marker, end_marker): | |
""" | |
Extracts a substring from 'text' that starts with the first occurrence of | |
'start_marker' and ends with the first occurrence of 'end_marker' right after it. | |
Parameters: | |
- text (str): The text from which to extract the substring. | |
- start_marker (str): The marker indicating the start of the substring. | |
- end_marker (str): The marker indicating the end of the substring. | |
This file contains hidden or 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
def multiSeries(varList,myKey,first='2018',last='2023'): | |
""" | |
Takes a list of variables and a key and makes a post request to the BLS. | |
- Input: varList = a list of strings containing the series names | |
- Input: myKey = a string containing your BLS API key | |
- Input: first = (optional) a string representing the starting year (integer) | |
- Input: last = (optional) a string representing the last year (integer) | |
- Output: new_df = a data frame containing the data collected | |