ENH: Add an option to json_normalize() to protect nested object(s) against flattening #40432
Labels
Duplicate Report
Duplicate issue or pull request
Enhancement
IO JSON
read_json, to_json, json_normalize
Needs Discussion
Requires discussion from core team before further action
Nested Data
Data where the values are collections (lists, sets, dicts, objects, etc.).
Is your feature request related to a problem?
Not really. I simply wish I could use pandas to protect a nested structure / object / dict against flattening when using pd.json_normalize() on a JSON object, for example an API response.
Describe the solution you'd like
Something like this (see below for a complete example):
API breaking implications
I have no detailed idea what this could/would break.
Describe alternatives you've considered
My current workaround is to duplicate the DataFrame; building one without normalizing, the other with. Keeping only the protected column(s) of the one which hasn't been normalized and concatenating them to the other. Remove redundant columns on the final DataFrame.
Additional context
Here's a dummy example:
Then:
Desired behaviour:
which would lead to:
Thanks for reading.
The text was updated successfully, but these errors were encountered: