close

[Solved] AttributeError: ‘numpy.float64’ object has no attribute ‘log10’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error AttributeError: ‘numpy.float64’ object has no attribute ‘log10’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How AttributeError: ‘numpy.float64’ object has no attribute ‘log10’ Error Occurs?

Today I get the following error AttributeError: ‘numpy.float64’ object has no attribute ‘log10’ in python.

How To Solve AttributeError: ‘numpy.float64’ object has no attribute ‘log10’ Error ?

  1. How To Solve AttributeError: 'numpy.float64' object has no attribute 'log10' Error ?

    To Solve AttributeError: 'numpy.float64' object has no attribute 'log10' Error I had a similar error message when using the standard deviation (np.std) instead of np.log10:

  2. AttributeError: 'numpy.float64' object has no attribute 'log10'

    To Solve AttributeError: 'numpy.float64' object has no attribute 'log10' Error I had a similar error message when using the standard deviation (np.std) instead of np.log10:

Solution 1

numpy.log10 is a “ufunc”, and the method Series.apply(func) has a special test for numpy ufuncs which makes test.apply(log10) equivalent to np.log10(test). This means test, a Pandas Series instance, is passed to log10. The data type of test is object, which means that the elements in test can be arbitrary Python objects. np.log10 doesn’t know how to handle such a collection of objects (it doesn’t “know” that those objects are, in fact, all np.float64 instances), so it attempts to dispatch the calculation to the individual elements in the Series. To do that, it expects the elements themselves to have a log10 method. That’s when the error occurs: the elements in the Series (in this case, np.float64 instances) do not have a log10 method.

A couple alternative expression that should do what you want are np.log10(test.astype(np.float64)) or test.astype(np.float64).apply(np.log10). The essential part is that test.astype(np.float64) converts the data type of the Series object from object to np.float64.

Solution 2

I had a similar error message when using the standard deviation (np.std) instead of np.log10:

‘AttributeError: ‘numpy.float64’ object has no attribute ‘sqrt’,

and this although I had previously converted the Pandas object X to a numpy array via np.asarray(X).

I could solve this problem by applying the above-mentioned solution:

X = pd.read_excel('file.xls')
Y = np.asarray(X).astype(np.float64)
Z = np.std(Y,axis=0)

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read