Skip to content

Commit

Permalink
DOC: add example on json_normalize (#16438)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzgao authored and jorisvandenbossche committed Aug 18, 2017
1 parent 24b6349 commit 34c4ffd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions doc/source/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2020,6 +2020,13 @@ 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)
.. ipython:: python
data = [{'state': 'Florida',
'shortname': 'FL',
'info': {
Expand Down
11 changes: 10 additions & 1 deletion pandas/io/json/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ 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'}]
>>> 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
>>> data = [{'state': 'Florida',
... 'shortname': 'FL',
... 'info': {
Expand All @@ -150,7 +160,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
Expand Down

0 comments on commit 34c4ffd

Please sign in to comment.