Flatten the JSON into a DataFrame
This commit is contained in:
parent
7909def8e2
commit
7eba74b3ef
|
@ -15,7 +15,12 @@ FILES = {
|
|||
"home-delivery": "data/home-delivery.json",
|
||||
}
|
||||
COLUMNS = {
|
||||
"cycling-paths": ["geo_shape", "statut", "record_timestamp", "complement"],
|
||||
"cycling-paths": [
|
||||
["fields", "geo_shape", "coordinates"],
|
||||
"statut",
|
||||
"record_timestamp",
|
||||
"complement",
|
||||
],
|
||||
"relay-parking": [
|
||||
"societe",
|
||||
"nb_places_dispositif_environ",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from json import load
|
||||
from pandas import json_normalize, DataFrame
|
||||
from pandas import json_normalize, DataFrame, set_option
|
||||
from constants import FILES, COLUMNS
|
||||
|
||||
|
||||
|
@ -17,11 +17,5 @@ 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)
|
||||
df = json_normalize(data=json, record_path=["records"], errors="ignore",)
|
||||
return df
|
||||
|
||||
|
||||
create_dataframe("cycling-paths")
|
||||
|
|
|
@ -29,6 +29,3 @@ def request_dataset(dataset):
|
|||
response.raise_for_status()
|
||||
data = response.json()
|
||||
save_json(data=data, dataset=dataset)
|
||||
|
||||
|
||||
request_dataset("deconfinement-pistes-cyclables-temporaires")
|
||||
|
|
Loading…
Reference in New Issue