10
python 3.9.2-3
pandas 2.0.0
pandas-io           0.0.1
Error: 
from pandas.io.json import json_normalize
ImportError: cannot import name 'json_normalize' from 'pandas.io.json' (/home/casaos/.local/lib/python3.9/site-packages/pandas/io/json/__init__.py)

Apparently this was a problem early on in the pre 1x days of pandas, but seems to have resurfaced. Suggestions?

I'm running a script which was functional previously, but migrating it to a new host. It errors out on the line:

from pandas.io.json import json_normalize

and throws the error

ImportError: cannot import name 'json_normalize' from 'pandas.io.json' (/home/casaos/.local/lib/python3.9/site-packages/pandas/io/json/__init__.py)

I've attempted to reinstall pandas ('install' option), remove and reinstall, and 'install --force-reinstall' all performed as root so that the base install of python3 has it installed as opposed to a single user

1
  • 11
    pandas.io.json.json_normalize was deprecated and removed in the newest version. Use pandas.json_normalize. Also, the tutorial you were following is most probably severely outdated. You are on your own now. Commented Apr 23, 2023 at 7:48

2 Answers 2

12

This was indeed the solution simply removing the import line. I'd have liked an attribute to check to determine the pandas version installed easily, but have to settle for a try:except: to determine if the import is needed.

pandas.io.json.json_normalize was deprecated and removed in the newest version. Use pandas.json_normalize. Also, the tutorial you were following is most probably severely outdated. You are on your own now. – Ξένη Γήινος Apr 23 at 7:48

Sign up to request clarification or add additional context in comments.

Comments

1

The pandas.io.json.json_normalize import has been deprecated since pandas 1.0.0 and was removed in pandas 2.0.0. Pandas 1.0.0 was released on Jan 30, 2020, and pandas.json_normalize has been a valid import since that date, so unless you're using an extremely old version of pandas, e.g. pandas<=0.25.3, you can safely remove the import from pandas.io.json import json_normalize from your code if it exists and replace function calls such as json_normalize(...) or pd.io.json.json_normalize(...) by pd.json_normalize(...).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.