Module pandas has no attribute json_normalize ( Solved )

[ad_1]

If you have JSON data then you can convert it into a Flat table using the pandas json_normalize method. But sometimes while using it you can get the error module pandas has no attribute json_normalize. In this entire tutorial, you will learn how to solve this issue in an easy method.

What is JSON?

JSON is known as JavaScript Object Notation. It is a lightweight format for storing and giving data to the world. If you have built JSON responses then you can use it in many applications like mobile apps, web applications e.t.c easily. It uses endpoints for sending data from one client to another.

The root cause of module pandas has no attribute json_normalize

The root cause for getting this attributeError: module pandas has no attribute json_normalize is that you must be using the newer version of the panda’s package.

The older version of the pandas ( Before Pandas 1.0.3 ) was using the pandas.io module for importing and implementing the json_normalize. Therefore you are getting the module pandas has no attribute json_normalize error for the newer version.

from pandas import json_normalize

Output

AttributeError: module 'pandas' has no attribute 'json_normalize'

 

Solution

The solution to the above AttributeError is that you have to downgrade the pandas to the version before 1.0.3. As you have to import the json_nomralize module from the pandas package directly in the newer version that is from pandas import json_normalize.

You will not get the pandas has no attribute json_normalize error when you will run the below lines of code.

from pandas.io.json import json_normalize
data = {"name":["Sahil","Rob","Maya","John"],"age":[20,25,35,40]}
json = json_normalize(data)
print(json)

Output

Output after applying json_normalize on the data
Output after applying json_normalize on the data

The other way to solve this issue is that you should upgrade or install the latest pandas version to the latest version and then directly use the pandas.json_normalize() method on your dataset.

Use the below command to upgrade to the latest version.

pip3 install -U pandas

Now again you will run the above lines of code you will not get the error.

Conclusion

Sometimes we get the AtrributeError when We are using the other versions of the python packages. The above case was in this category. You were getting the module pandas has no attribute json_normalize error because of the different version of the pandas package.

I hope this tutorial has solved your query. If you have doubts or suggestions 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.



[ad_2]

Source link