Skip to content

Commit 8edc40e

Browse files
jowensjreback
authored andcommitted
ENH: json_normalize now takes a user-specified separator
closes #14883
1 parent ec84ae3 commit 8edc40e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

doc/source/whatsnew/v0.20.0.txt

+4
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ Other Enhancements
303303
- ``pandas.io.json.json_normalize()`` gained the option ``errors='ignore'|'raise'``; the default is ``errors='raise'`` which is backward compatible. (:issue:`14583`)
304304
- ``.select_dtypes()`` now allows the string 'datetimetz' to generically select datetimes with tz (:issue:`14910`)
305305
- The ``.to_latex()`` method will now accept ``multicolumn`` and ``multirow`` arguments to use the accompanying LaTeX enhancements
306+
306307
- ``pd.merge_asof()`` gained the option ``direction='backward'|'forward'|'nearest'`` (:issue:`14887`)
307308
- ``Series/DataFrame.asfreq()`` have gained a ``fill_value`` parameter, to fill missing values (:issue:`3715`).
308309
- ``Series/DataFrame.resample.asfreq`` have gained a ``fill_value`` parameter, to fill missing values during resampling (:issue:`3715`).
@@ -318,6 +319,9 @@ Other Enhancements
318319
- Re-enable the ``parse_dates`` keyword of ``read_excel`` to parse string columns as dates (:issue:`14326`)
319320
- Added ``.empty`` property to subclasses of ``Index``. (:issue:`15270`)
320321

322+
- ``pandas.io.json.json_normalize()`` has gained a ``sep`` option that accepts ``str`` to separate joined fields; the default is ".", which is backward compatible. (:issue:`14883`)
323+
324+
321325
.. _ISO 8601 duration: https://en.wikipedia.org/wiki/ISO_8601#Durations
322326

323327

pandas/tests/io/json/test_normalize.py

+15
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ def test_empty_array(self):
6767
expected = DataFrame()
6868
tm.assert_frame_equal(result, expected)
6969

70+
def test_simple_normalize_with_default_separator(self):
71+
result = json_normalize({'A': {'A': 1, 'B': 2}})
72+
expected = DataFrame([[1, 2]], columns={'A.A', 'A.B'})
73+
tm.assert_frame_equal(result, expected)
74+
75+
def test_simple_normalize_with_user_specified_separator(self):
76+
result = json_normalize({'A': {'A': 1, 'B': 2}}, sep='_')
77+
expected = DataFrame([[1, 2]], columns={'A_A', 'A_B'})
78+
tm.assert_frame_equal(result, expected)
79+
80+
def test_simple_normalize_with_user_specified_unicode_separator(self):
81+
result = json_normalize({'A': {'A': 1, 'B': 2}}, sep=u'\u03c3')
82+
expected = DataFrame([[1, 2]], columns={u'A\u03c3A', u'A\u03c3B'})
83+
tm.assert_frame_equal(result, expected)
84+
7085
def test_more_deeply_nested(self):
7186
data = [{'country': 'USA',
7287
'states': [{'name': 'California',

0 commit comments

Comments
 (0)