5

I have a json variable named json_results and I am running pandas.json_normalize(json_results). It raises the following error:

in _json_normalize
    raise NotImplementedError
NotImplementedError

How can I resolve this?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
pwlt1998
  • 51
  • 1
  • 2

3 Answers3

7

This error can happen if you pass a JSON string to json_normalize, not an already decoded JSON object.

>>> import json
>>> import pandas as pd

>>> s = '{"hello": "world"}'
>>> pd.json_normalize(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../lib/python3.7/site-packages/pandas/io/json/_normalize.py", line 423, in _json_normalize
    raise NotImplementedError
NotImplementedError

>>> d = json.loads(s)
>>> pd.json_normalize(d)
   hello
0  world

If this is the case, use json.loads (or an equivalent Pandas function) first.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
1

Try from_records method like:

import json
import pandas as pd

s = '{"Column 1":{"Row 1":"Value 1","Row 2":"Value 2","Row 3":"Value 3"},' \
    '"Column 2":{"Row 1":"Value 4","Row 2":"Value 5","Row 3":"Value 6"}}'
result = pd.DataFrame.from_records(json.loads(s))
print(result)

Output:

      Column 1 Column 2
Row 1  Value 1  Value 4
Row 2  Value 2  Value 5
Row 3  Value 3  Value 6

info() method output:

<class 'pandas.core.frame.DataFrame'>
Index: 3 entries, Row 1 to Row 3
Data columns (total 2 columns):
 #   Column    Non-Null Count  Dtype 
---  ------    --------------  ----- 
 0   Column 1  3 non-null      object
 1   Column 2  3 non-null      object
dtypes: object(2)
0

Are you importing json_normalize like this:

from pandas.io.json import json_normalize

If so, import pandas and then try calling json_normalize like this:

pd.json_normalize()

Instead of:

json_normalize()

This is what fixed this issue for me.

rob0tst0p
  • 136
  • 9