def get_bg_dataframe(id_str):
"""
Function to convert the json file to a pandas dataframe.
It takes in the string of the id and looks for the devicestatus.json file.
All data should be stored such that in the directory where main.py lies,
there is a directory called "data". Inside this directory,
there is another directory with just the ID Number. Inside this data folder lies the
devicestatus.json file, which contains the data. If the file is not in the path given,
it raises an IOError. The path should look like the following example:
./data/12345678/devicestatus.json
Input: id_str ID number as a string
Output: bg_df Pandas dataframe of all of the data from ./data/[id_str]/devicestatus.json
Usage: bg_df = get_bg_dataframe("12345678")
"""
try:
file_location = "./data/" + id_str + "/devicestatus.json"
bg_df = pd.read_json(file_location) #Opens the data file and reads in the data into a dataFrame
except:
raise IOError(file_location + " is not a valid file.")
print
print("{} total entries.".format(len(bg_df)))
return bg_df
#Function to find the indices for the given start and end date strings
评论列表
文章目录