From 2a6478f9167d9321ef5ce71c7184e39ce8e93f05 Mon Sep 17 00:00:00 2001 From: Guilherme Botelho Date: Thu, 26 Dec 2024 14:30:18 -0300 Subject: [PATCH] altera transform_to_nested_structure --- pipelines/utils/pretreatment.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pipelines/utils/pretreatment.py b/pipelines/utils/pretreatment.py index 19f6f1bea..fb5a0f045 100644 --- a/pipelines/utils/pretreatment.py +++ b/pipelines/utils/pretreatment.py @@ -22,8 +22,12 @@ def transform_to_nested_structure(data: pd.DataFrame, primary_keys: list) -> pd. data["content"] = data.apply( lambda row: json.dumps( { - key: value if not pd.isna(value) else None - for key, value in row[content_columns].to_dict().items() + key: ( + row[key] + if isinstance(row[key], (list, dict)) or not pd.isna(row[key]) + else None + ) + for key in content_columns } ), axis=1,