28 lines
591 B
Python
28 lines
591 B
Python
from json import load
|
|
from pandas import json_normalize, DataFrame
|
|
from constants import FILES, COLUMNS
|
|
|
|
|
|
def open_json(dataset) -> dict:
|
|
"""
|
|
Loads a dictionary with data from a JSON file
|
|
"""
|
|
with open(FILES[dataset]) as f:
|
|
json = load(f)
|
|
return json
|
|
|
|
|
|
def create_dataframe(dataset) -> DataFrame:
|
|
"""
|
|
Creates a DataFrame from a JSON file
|
|
"""
|
|
json = open_json(dataset)
|
|
df = json_normalize(
|
|
data=json, record_path=["records"], meta=COLUMNS[dataset], errors="ignore",
|
|
)
|
|
print(df)
|
|
return df
|
|
|
|
|
|
create_dataframe("cycling-paths")
|