13

My Jupiter notebook was crushed, so I have to reinstall the notebook, but in the new Jupiter notebook, I cannot run pandas.

import pandas as pd
AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_6860/4080736814.py in <module>
----> 1 import pandas as pd

~\anaconda3\lib\site-packages\pandas\__init__.py in <module>
     20 
     21 # numpy compat
---> 22 from pandas.compat import (
     23     np_version_under1p18 as _np_version_under1p18,
     24     is_numpy_dev as _is_numpy_dev,

~\anaconda3\lib\site-packages\pandas\compat\__init__.py in <module>
     12 import warnings
     13 
---> 14 from pandas._typing import F
     15 from pandas.compat.numpy import (
     16     is_numpy_dev,

~\anaconda3\lib\site-packages\pandas\_typing.py in <module>
     82 # array-like
     83 
---> 84 ArrayLike = Union["ExtensionArray", np.ndarray]
     85 AnyArrayLike = Union[ArrayLike, "Index", "Series"]
     86 

AttributeError: module 'numpy' has no attribute 'ndarray'

I have tried to rename or delete the numpy.py, but it didn't work.

1
  • uninstall and reinstall numpy? pip uninstall -y numpy and then pip install numpy Commented Oct 13, 2021 at 0:56

5 Answers 5

4

The problem is not with Pandas. This is due to NumPy. I had a similar issue and this is what I did.

Ran python -c "import numpy as np; print(np.__file__); print(np.ndarray)". The expect output will contain the location of your installed NumPy package and <class 'numpy.ndarray'> for the second print statement. In my case, it seemed that NumPy package was located in ~/.local.

I tried reinstalling NumPy in conda, but the location was still the same. So, as per this solution, I deleted ~/.local. Then the error disappeared.

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

2 Comments

in windows where is it ?
@AhmedCanUnbay I am not sure.
2

For me none of the above solutions fixed the issue. The only way it worked was I cleaned up all my python environments.

  • Removed manually installed python versions at various locations such as usr/local/bin
  • cleaned up PATH
  • Removed all but python 3.11 from brew.
  • Ran brew cleanup and resolved all warnings/issues.
  • Re-installed command line tools since I had been using the system installed python version for various projects.
  • Created a fresh virtual environment using brew's python3.11 as the base interpreter. Post this both numpy and pandas were not present and were installed fresh. No issues anymore.

Comments

0

If you're facing this issue on mac... I resolved it by installing numpy via Homebrew

brew install numpy

This fixed the issue for me.

Comments

-1

Just try to degrade or upgrade the numpy versions. It works for me...

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
-1

In my case I had a script called numpy.py.

Answer found here -> https://discuss.python.org/t/numpy-y-pandas-problem-import/13460/2

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.