From 34c4ffd7c454848311f71e6869b5cad4bc132449 Mon Sep 17 00:00:00 2001 From: zzgao Date: Fri, 18 Aug 2017 08:27:20 -0700 Subject: [PATCH] DOC: add example on json_normalize (#16438) --- doc/source/io.rst | 7 +++++++ pandas/io/json/normalize.py | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/doc/source/io.rst b/doc/source/io.rst index e6b51b7e2f45c..e338407361705 100644 --- a/doc/source/io.rst +++ b/doc/source/io.rst @@ -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': { diff --git a/pandas/io/json/normalize.py b/pandas/io/json/normalize.py index 401d8d9ead2b8..72776ed01de15 100644 --- a/pandas/io/json/normalize.py +++ b/pandas/io/json/normalize.py @@ -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': { @@ -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