ChatGPT解决这个技术问题 Extra ChatGPT

Importing Pandas gives error AttributeError: module 'pandas' has no attribute 'core' in iPython Notebook

I am running a iPython notebook via the Anaconda Navigator app (version 1.1.0). When I want to import pandas it gives me a strange error. I thought the Anaconda app included the pandas package?

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-af55e7023913> in <module>()
----> 1 import pandas as pd

/Users/bertcarremans/anaconda/lib/python3.5/site-packages/pandas/__init__.py in <module>()
 37 import pandas.core.config_init
 38 
---> 39 from pandas.core.api import *
 40 from pandas.sparse.api import *
 41 from pandas.stats.api import *

/Users/bertcarremans/anaconda/lib/python3.5/site-packages/pandas/core/api.py in <module>()
  8 from pandas.core.common import isnull, notnull
  9 from pandas.core.categorical import Categorical
---> 10 from pandas.core.groupby import Grouper
 11 from pandas.core.format import set_eng_float_format
 12 from pandas.core.index import (Index, CategoricalIndex, Int64Index,

/Users/bertcarremans/anaconda/lib/python3.5/site-packages/pandas/core/groupby.py in <module>()
 16                               DataError, SpecificationError)
 17 from pandas.core.categorical import Categorical
---> 18 from pandas.core.frame import DataFrame
 19 from pandas.core.generic import NDFrame
 20 from pandas.core.index import (Index, MultiIndex, CategoricalIndex,

/Users/bertcarremans/anaconda/lib/python3.5/site-packages/pandas/core/frame.py in <module>()
 37                                    create_block_manager_from_arrays,
 38                                    create_block_manager_from_blocks)
---> 39 from pandas.core.series import Series
 40 from pandas.core.categorical import Categorical
 41 import pandas.computation.expressions as expressions

/Users/bertcarremans/anaconda/lib/python3.5/site-packages/pandas/core/series.py in <module>()
 33 from pandas.core.internals import SingleBlockManager
 34 from pandas.core.categorical import Categorical, CategoricalAccessor
---> 35 import pandas.core.strings as strings
 36 from pandas.tseries.common import (maybe_to_datetimelike,
 37                                    CombinedDatetimelikeProperties)

AttributeError: module 'pandas' has no attribute 'core'
Do you have a file called pandas.py in the directory? Try import pandas;print(pandas.__file__)
@Padraic Cunningham: No pandas.py file in the directory. When I type the Python code you mentioned, it produces the same error. I also want to add that I am working on a Mac. Does this conflict with the Python provided by Apple perhaps?
Yep, should have noticed that from the traceback, I cannot imagine there being any overlap between your system and the anaconda installed packages. If you do a pip/conda update do you see the same error?
type 'which python' and see what python you are using. Is it the one provided by Anaconda package?
@Padraic Cunningham: when I do the update of the pandas package, the error persists.

D
Dataman

"Have you tried turning it off and on again?" (Roy of The IT crowd)

This happened to me today, which is why I ended up to this page. Seeing that error was weird since, recently, I have not made any changes in my Python environment. Interestingly, I observed that if I open a new notebook and import pandas I would not get the same error message. So, I did shutdown the troublesome notebook and started it again and voila it is working again!

Even though this solved the problem (at least for me), I cannot readily come up with an explanation as to why it happened in the first place!


The issue happened to me because I stopped the execution of import pandas cell when I noticed it was taking unusually long time. When I re-ran the cell immediately after stopping, it threw the AttributeError . Shutting down and restarting the notebook resolved the issue.
It happened to me because I upgraded pandas while using it on the IDE (Spyder in my case). Restarted spyder and fixed the issue. Thanks for the heads up.
same situation here, pandas 0.25.3. Shutdown and restart worked.
I faced the same exact situation. Pandas 0.25.3. Shutdown and restart of Jupyter notebook worked for me.
Same story here. I did a keyboard interrupt during importing pandas. As mentioned by the others, closing the notebook, deactivating and then reactivating the virtual environment and reopening the notebook solved the issue. Thanks for your help.
a
anothernode

There's this bug in the latest version of pandas (pandas 0.23) that gives you an error on importing pandas.

But this can be easily fixed by installing an earlier version of pandas (pandas 0.22) using the command pip install pandas==0.22 on Windows Command Prompt.


This fails on MacOS with ARM. (M1)
C
Community

Apparently the error I got when trying to import pandas for the first time was ValueError: unknown locale: UTF-8

Trying to import again afterwards, gave another error as described in my question above.

I found the solution to solve the ValueError on IPython Notebook locale error

After updating my bash profile, the error AttributeError: module 'pandas' has no attribute 'core' did not appear anymore.


Would be interesting to know how you updated your Bash profile : )
S
Senthilkumar Gopal

There is an other weird reason this happens. If you have a file called pandas.py or a directory called pandas in the same or nested levels, that library is used instead and fails to work. Rename the folder and restart the env and it started working. Faced this


Thank you! This was the obscure one for me... I had a pandas.py I was using to test things out temporarily and it was getting picked up.
Thanks man, I spent two hours reading and finding a solution and the problem was the name of my python file was pandas.py, so the import pandas was importing itself.
J
Josh Peak

I had a similar issue since I installed pandas using python -m pip install pandas --upgrade --user which installed a conflicting version in my user python packages directory, masking the Anaconda installed version that other dependencies relied upon.

conda list | grep pandas
pandas == 0.23.4

python -m pip list | grep pandas
pandas == 0.24.0

So uninstalling the user directory masked version cleaned up the issue for me.

python -m pip uninstall pandas

For reference all possible python packages are installed in the directories listed from this command:

python -m site

Might be worth iterating through these and checking for duplicates.

Edit: Since my original answer I learnt you can run:

python -m pip list -v

And it shows the directory the library is installed. This often shows whether the library you want is in a virtual environment, conda environment, user directory, system site packages etc.


Thanks. For me though I had to do python -m pip uninstall pandas and then do pip install pandas and all started working again!
Both of those are the answers
d
dooms

Try in your console

conda install pandas

and see what's the message given.


When I do this, I get that all requested packages already installed showing pandas, 0.18.0 and np110py35_0
yes, I even tried a reinstall with the Python 2.7.6 version of Anaconda, but nothing helps.
M
Maddy Anand

You are getting this is because you are using a Anaconda distribution of Jupyter notebook. So just do conda install pandas restart your jupyter notebook and rerun your cell. It should work. If you are trying this on a Virtual Env try this

conda create -n name_of_my_env python This will create a minimal environment with only Python installed in it. To put your self inside this environment run:

2 source activate name_of_my_env On Windows the command is: activate name_of_my_env The final step required is to install pandas. This can be done with the following command:

conda install pandas To install a specific pandas version:

conda install pandas=0.20.3

To install other packages, IPython for example:

conda install ipython To install the full Anaconda distribution:

conda install anaconda

If you need packages that are available to pip but not conda, then install pip, and then use pip to install those packages:

conda install pip pip install django Installing from PyPI pandas can be installed via pip from PyPI.

pip install pandas Installing with ActivePython

Hope this helps.


k
koalagreener

I have just solved this problem. Recently, I changed my language setting of my MacBook from English-UK to Chinese. And I suppose that setting will also change the setting in the "locale." Becuase when I switched back, I found that the setting of locale had been changed again, and I am fine to import the pandas again,.

So if you have changed the language setting recently, you may worth to have a try change it back.


This is correct; This occurred when I changed from English-US to Chinese.
C
CathyQian

I recently came across the same problem right after I installed Pandas 0.23 in Anaconda Prompt. The solution is simply to restart the Jupyter Notebook which reports the error. May it helps.


N
Niraj D Pandey

I face similar issue while importing TensorFlow. If you are using Tensorflow which uses Pandas library, I suggest restarting your kernel of Anaconda. This works for me.


K
Kaustub Gupta

I got the same error for pandas latest version. Then saw this warning

FutureWarning: 'pandas.tools.plotting.scatter_matrix' is deprecated, import 'pandas.plotting.scatter_matrix' instead.

This shall work for you.


H
Hoppo

I can confirm this issue is due to pandas 0.23.

Uninstall and then reinstall 0.22.

pip uninstall pandas
pip install pandas==0.22

Hope this could solve the problem.


this solved it for me, though I simply installed the latest pandas
b
braulio

yes, the Anaconda distribution includes pandas, type

conda list

to get a list of the packages installed.


S
Shu Zhang

Press Ctrl+C to shut down the jupyter notebook, close all jupyter notebook windows Reopen it by typing jupyter notebook in cmd prompt.


s
shaimar

I had the same problem after installing TensorFlow package, which downgraded my pandas version from 2.23 to 2.22. I tried all the solutions proposed above + the one suggested by post author, linked here. What eventually worked for me was to reinstall Anaconda distribution.


v
veben

I faced the same problem and I solved it using the following steps:

Open "Anaconda Prompt" [For Windows] Run "conda uninstall pandas". Run "conda install pandas".

Actually, there is a pandas version conflict, which would get resolved automatically by following the above steps.

Stay Blessed!


p
pallavi sangapu - Intel

You can try the below command

conda upgrade --all

and try to restart the notebook.

Hope this helps


S
SearchTools-Avi

I got this from using the Anaconda default environment instead of my custom one with pandas installed.

Changing to the right environment and reopening the Jupyter notebooks did not fix this for me (python 3.7, pandas 0.23.0). Restarting Anaconda did.


A
Arjjun

I had exact issue and here is how I fixed:

I found out that I had first installed Keras then installed pandas in my virtual env. When you install keras, pandas is shipped with it. Do not need to pip install pandas.

I tested this hypothesis by creating new virtual environment and wala... pandas appeared without me installing it. Thus I came to the conclusion that pandas is automatically installed when you pip install keras.


S
Shivam Jindal

close and open your text editor , the problem will be solved , must have happened while you were working on a large dataset


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now