1

I am trying to get a column using following command from an Excel file

i = pd.read_excel('filename.xlsx', sheet_name='sheet1')['column1']

In the past code was working well but today it suddenly stopped working with error.

I tried using different version of Pandas and NumPy but this did not work and gave the following error:

AttributeError: module 'numpy' has no attribute 'float'. np.float was a deprecated alias for the builtin float. To avoid this error in existing code, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

Does anyone know how to fix this instead of painfully trying different versions of Pandas and/or numpy?

In past code was working well but now it is not working at all.

3
  • I'm able to access numpy.float with NumPy 1.23.5. It produces a warning but works fine otherwise. Commented Apr 3, 2023 at 6:35
  • Try: pip install "numpy<1.24.0" "pandas==1.5.3". Don't forget to restart your kernel if you use a notebook. Commented Apr 3, 2023 at 6:39
  • What is trying to use np.float? Your own code, or something you import? You seem to think it is pandas. Does the error traceback actually tell you that, or are you just guessing. The latest pandas version should have corrected this issue. Commented Apr 3, 2023 at 7:58

4 Answers 4

1

Instead of downgrading pandas or numpy like suggested in other answers, try updating the package openpyxl to a version >= 3.0.6. This is the version which fixed that bug.

openpyxl is the package which is responsible for reading excel sheets into pandas.

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

1 Comment

could you show a traceback that identifies this module as the problem?
0

I simply uninstalled anaconda then re-installed. It solved the issue. Spent so many hours trying to debug but uninstallation and reinstallation of Anaconda fixed the issue for me. Not the ideal way to fix issue but need to move on ...

Thank for the responses, Friends.

Comments

0

I had a similar attribute error when I tried to upgrade Numpy to version 1.24.4. I tried to revert to an earlier version of Numpy with

pip install numpy==1.23.4 

and it worked just fine.

Thanks to @ForceBru for suggesting this in the comments.

Comments

-1

Refer to this link

https://numpy.org/doc/1.20/reference/arrays.scalars.html#other-aliases

Try using np.float_, otherwise there are lot of other options on the reference from which you can select the one that satisfies your need.

You can use this by directly mentioning the dtype to be used for the column in a dictionary:

pd.read_excel(the_file, dtype = {"col1":np.float_})

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.