Skip to content

Instantly share code, notes, and snippets.

View ArieBeresteanu's full-sized avatar
💎
Partially identified, always sharp

ArieBeresteanu

💎
Partially identified, always sharp
View GitHub Profile
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',
@ArieBeresteanu
ArieBeresteanu / readJSONfile.py
Created January 28, 2025 23:55
reading a JSON file from your hard drive
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
@ArieBeresteanu
ArieBeresteanu / gist:1bdef062079a55c47fd90946b70f1a51
Created March 20, 2024 20:37
Extracts a sub string from a text
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.
@ArieBeresteanu
ArieBeresteanu / multiSeries.py
Created February 21, 2024 01:17
A function that calls the BLS' API and asks for a list of variables
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