How to Solve iPython Notebook AttributeError: module ‘pandas’ has no attribute ‘core’ when Importing Pandas in python

How to Solve iPython Notebook AttributeError: module ‘pandas’ has no attribute ‘core’ when Importing Pandas in python is an error which occurs when there is something wrong with your notebook.

This post is my attempt to explain to you why this error occurs and how you can solve it, I will also include multiple solutions that could be considered as alternative fixes to the error.

Exploring the Error : iPython Notebook AttributeError: module ‘pandas’ has no attribute ‘core’ when Importing Pandas in python

This is an error which occurs when there is something wrong with your notebook.

The error should look like this. Double check in order to avoid mixing between errors.

                                                                       #
AttributeError Traceback (most recent call last)
<ipython-input-4-af55e7023913> in <module>()
----> 1 import pandas as pd
---> 18 from pandas.core.frame import DataFrame
.....
 34 from pandas.core.categorical import Categorical, CategoricalAccessor
---> 35 import pandas.core.strings as strings
 36 from pandas.tseries.common import (maybe_to_datetimelike,
AttributeError: module 'pandas' has no attribute 'core'
                                                                       #

Bellow are the solutions which worked for me and will help you to successfully solve your problem.

Solution 1 : Shutdown the old notebook and started it again

Apparently, for many people, when they open a new notebook and import pandas the error disappears. But that is not the case for the old notebook.

So, the solution is easy. Shutdown the old notebook and started it again and the error should be gone.

The error is usually caused after you stop the execution of the notebook either on purpose or by mistake.

When you open it again, you get the error.

If this solution does not fix your problem you can try the second solution.

Solution 2 : Rename pandas.py or the directory you called pandas

Ok, there is another very unusual reason why this error might happen. Sometimes you manually create a file and you call it pandas.py or you create a directory and name it pandas.

The above can cause confusion, I do not really know why. But, if you change the name of the .py module from pandas to something else the error will probably disappear. Also this applies to the directory called pandas.

The solution should be enough, please try the final solution if this fails.

Solution 3 : install an earlier version of pandas

The problem is reportedly a bug in the newest versions of pandas. The last solution in this blog post is to downgrade to an earlier version of pandas.

This is the official list of pandas versions https://pandas.pydata.org/docs/whatsnew/index.html

For example if you have pandas version 1.4, you can install the version 1.3 of pandas

                                                                       #
pip install pandas==1.3
                                                                       #

If this has solved your issue, congratulations.

If this article has been useful for your particular case, consider donating to our Kofi account, there is a red button at the top of this page.

Summing-up

The article is over, I hope I have been able to help you solve this error or at least guide you in the right direction, check out other solutions to different errors you can do that by using the search bar on top of this page.

Keep learning, keep coding guys, cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/