'Why does pandas.json_normalize(json_results) raise a NotImplementedError?
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?
Solution 1:[1]
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.
Solution 2:[2]
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.
Solution 3:[3]
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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | rob0tst0p |
Solution 2 | mkrieger1 |
Solution 3 | Artem S. Zhelonkin |