-
-
Notifications
You must be signed in to change notification settings - Fork 18k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOC: add example on json_normalize #16438
Changes from 2 commits
e9fed01
c85a318
c25252f
88fe776
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1991,6 +1991,18 @@ Normalization | |
pandas provides a utility function to take a dict or list of dicts and *normalize* this semi-structured data | ||
into a flat table. | ||
|
||
.. ipython:: python | ||
|
||
from pandas.io.json import json_normalize | ||
data = [ | ||
{'id': 1, 'name': {'first': 'Coleen', 'last': 'Volk'}}, | ||
{'name': {'given': 'Mose', 'family': 'Regner'}}, | ||
{'id': 2, 'name': 'Faye Raker'} | ||
] | ||
json_normalize(data) | ||
|
||
.. _io.jsonl: | ||
|
||
.. ipython:: python | ||
|
||
from pandas.io.json import json_normalize | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to add this to the same same
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's OK to keep it as separate ipython blocks, if you want to have it render as two separate blocks (which can give some more structure to the examples). In this a case that is OK because it are two different examples, I think. You don't need to import json_normalize the second time |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,6 +135,19 @@ def json_normalize(data, record_path=None, meta=None, | |
Examples | ||
-------- | ||
|
||
>>> from pandas.io.json import json_normalize | ||
>>> data = [ | ||
... {'id': 1, 'name': {'first': 'Coleen', 'last': 'Volk'}}, | ||
... {'name': {'given': 'Mose', 'family': 'Regner'}}, | ||
... {'id': 2, 'name': 'Faye Raker'} | ||
... ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe here (and in io.rst), do a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||
>>> json_normalize(data) | ||
id name name.family name.first name.given name.last | ||
0 1.0 NaN NaN Coleen NaN Volk | ||
1 NaN NaN Regner NaN Mose NaN | ||
2 2.0 Faye Raker NaN NaN NaN NaN | ||
|
||
>>> from pandas.io.json import json_normalize | ||
>>> data = [{'state': 'Florida', | ||
... 'shortname': 'FL', | ||
... 'info': { | ||
|
@@ -150,7 +163,6 @@ def json_normalize(data, record_path=None, meta=None, | |
... }, | ||
... 'counties': [{'name': 'Summit', 'population': 1234}, | ||
... {'name': 'Cuyahoga', 'population': 1337}]}] | ||
>>> from pandas.io.json import json_normalize | ||
>>> result = json_normalize(data, 'counties', ['state', 'shortname', | ||
... ['info', 'governor']]) | ||
>>> result | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was added on accident?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was to break the examples into two blocks which seem to be cleaner after checking with @DGrady. I can combine them into the same block if that's preferred
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, that looks good (based on screenshot below). I think you still want to remove this line though, otherwise it's creating a reference anchor to this point.