Importerror: cannot import name ‘json_normalize’ from ‘pandas’ ( Solved )

Importerror_ cannot import name 'json_normalize' from 'pandas'

Pandas is the best python library for manipulating datasets. It has many built-in functions that allow you to do so. But sometimes you may face errors like importerror: cannot import name ‘json_normalize’ from ‘pandas’ when you try to implement JSON in your project. If you are getting this error then this article is for you. In this entire tutorial, you will learn how to solve this error.

What is JSON ?

JSON is know as JavaScript Object Notation. It accept key value data. The format of the json file is .json. Most of developers use it to represent data that makes very easy for them to use that data from one application to another application. For example If you have build an api that communicate with json response then you can easily call the api from any apps like Android, web or desktop app.

Why the importerror: cannot import name ‘json_normalize’ from ‘pandas’ Occurs?

The function json_normalize()  function is used to convert the JSON data into the pandas dataframe. The main reason for getting this error is that the python interpreter is unable to find the json_normalize function in the panda’s library.

Suppose you have JSON data for the student. And if you will use this function to convert it to Pandas dataframe then you will get the cannot import name ‘json_normalize’ from ‘pandas’ error.
import pandas as pd

data = {

"name": "Roy",

"age": 20,
}

df = pd.json_normalize(data)

print(df)

Output

Importerror: cannot import name 'json_normalize' from 'pandas'

Solution of the cannot import name ‘json_normalize’ from ‘pandas’ Error

There can be various reasons for getting this importerror. The following are the reasons and solutions for solving this error.

Solution 1: Install the Pandas module

You may get this error as the pandas module is not installed in your system and you are using this function. To solve this error you have to install pandas module.

Use the below command to install pandas module in your system.

For python 3.xx

pip3 install pandas

For python 2.xx

pip install pandas
Install pandas module in the system
Install pandas module in the system

Solution 2: Reinstall the pandas module

Sometimes this importerror: cannot import name ‘json_normalize’ from ‘pandas’ error also come even the module is installed in your system. Therefore to remove this error you have to upgrade the module.

Open your terminal and use the command to Reinstall the panda’s module.

pip3 install --upgrade pandas

Solution 3: Update older versions of pandas

The json_normalize() function has been introduced in pandas 0.19.2. So if you are getting this error then you must be using the older version. To solve this error you have to update the panda’s module to greater than the 0.19.2 version.

You have to simply update the panda’s module.

pip3 install --upgrade pandas

Conclusion

In this article, you will learn how to solve the importerror: cannot import name ‘json_normalize’ from ‘pandas’ error. This error is caused when you try to use the json_normalize function from pandas. By following the steps in this tutorial, you will be able to successfully use this function in your project.

I hope you have liked this tutorial. If you have a query then you can contact us for more help.

 

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Sukesh ( Chief Editor ), a passionate and skilled Python programmer with a deep fascination for data science, NumPy, and Pandas. His journey in the world of coding began as a curious explorer and has evolved into a seasoned data enthusiast.
 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner