Add dataframes filtering

This commit is contained in:
coolneng 2020-05-27 21:25:08 +02:00
parent 67968a8ad3
commit 9a27a520b4
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
2 changed files with 31 additions and 3 deletions

View File

@ -14,3 +14,27 @@ files = {
"relay-parking": "data/relay-parking.json", "relay-parking": "data/relay-parking.json",
"home-delivery": "data/home-delivery.json", "home-delivery": "data/home-delivery.json",
} }
columns = {
"cycling-paths": ["geo_shape", "statut", "record_timestamp", "complement"],
"relay-parking": [
"societe",
"nb_places_dispositif_environ",
"parcs",
"geo_shape",
"cp",
"ville",
"adresse",
],
"home-delivery": [
"geo_shape",
"adresse",
"code_postal",
"nom_du_commerce",
"type_du_commerce",
"site_internet",
"record_timestamp",
"precisions",
"telephone",
"mail",
],
}

View File

@ -1,6 +1,6 @@
from json import load from json import load
from pandas import json_normalize, DataFrame from pandas import json_normalize, DataFrame
from app.constants import files from constants import files, columns
def open_json(dataset): def open_json(dataset):
@ -11,6 +11,10 @@ def open_json(dataset):
def create_dataframe(dataset): def create_dataframe(dataset):
json = open_json(dataset) json = open_json(dataset)
data = json_normalize(data=json["records"]) df = json_normalize(
df = DataFrame.from_dict(data=data) data=json["records"],
record_path=["fields"],
meta=columns[dataset],
errors="ignore",
)
return df return df