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.

Answer from Warren Weckesser on Stack Overflow
🌐
GitHub
github.com › scikit-learn › scikit-learn › issues › 3142
linear_model giving AttributeError: 'numpy.float64' object has no attribute 'exp' · Issue #3142 · scikit-learn/scikit-learn
May 10, 2014 - Per the stacktrace, I've tracked the problem to the lines in linear_model/base.py. I think that LinearClassifierMixin.decision_function is returning an array of dtype=object which makes np.exp() fail. None of the values in the array look to my eye like anything other than floats.
Published   May 10, 2014
Author   vm-wylbur
Discussions

python - Why isn't isnumeric working? - Stack Overflow
I was going through a very simple python3 guide to using string operations and then I ran into this weird error: In [4]: # create string string = 'Let\'s test this.' # test to see... More on stackoverflow.com
🌐 stackoverflow.com
python - 'numpy.float64' object has no attribute 'apply' - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
April 9, 2019
Numpy.int64 object has no attribute 'quantile'

It helps to post a full stack trace, but based on what you’ve said it sounds like you’re trying to call the quantile function on a single integer, rather than the whole column

More on reddit.com
🌐 r/pythontips
1
2
October 5, 2021
[deleted by user]
Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you. I think I have detected some formatting issues with your submission: Inline formatting (`my code`) used across multiple lines of code. This can mess with indentation. If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting. Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here . More on reddit.com
🌐 r/learnpython
6
1
August 28, 2022
People also ask

What causes the 'numpy float64 object has no attribute isnull' error in Python?
This error occurs when the user attempts to access an attribute that is not present in a numpy float64 object, particularly when attempting to access an element of a row that is a single element and happens to be a float.
🌐
copyprogramming.com
copyprogramming.com › howto › fixing-the-common-numpy-float64-object-has-no-attribute-isnull-error-in-python
Resolving the Widely Occurring Error in Python: 'isnull' is not ...
How can I fix the 'numpy float64 object has no attribute isnull' error in Python?
The community suggests using pd.isnull() or pd.isna(), or np.isnan() in some cases to fix the issue. Using different parameter names, such as "row" instead of "df", may also fix the error. Users can use the pandas.DataFrame.isnull method to detect missing values and return a boolean same-sized object indicating if the values are NA.
🌐
copyprogramming.com
copyprogramming.com › howto › fixing-the-common-numpy-float64-object-has-no-attribute-isnull-error-in-python
Resolving the Widely Occurring Error in Python: 'isnull' is not ...
What are some additional tips to avoid the 'numpy float64 object has no attribute isnull' error in Python?
Users may encounter errors related to appending values to a NumPy array using the append() function in regular Python. To avoid this error, users may benefit from using different methods, such as .tolist() or .values, to convert Series or DataFrame objects to NumPy arrays. Users may also benefit from using virtual environments, such as Anaconda or virtualenv, to manage dependencies and avoid version conflicts.
🌐
copyprogramming.com
copyprogramming.com › howto › fixing-the-common-numpy-float64-object-has-no-attribute-isnull-error-in-python
Resolving the Widely Occurring Error in Python: 'isnull' is not ...
🌐
Reddit
reddit.com › r/learnpython › numpy has not attribute?
r/learnpython on Reddit: Numpy has not attribute?
June 23, 2017 -

I am trying to plot a .txt file of lines of the form: filename.txt date magnitude V098550.txt 362.0 3.34717962317 but I am getting the error "numpy.float64' object has no attribute 'replace'". Does anyone know if this is a syntax error with numpy, or how I can resolve my issue?

import numpy as np
import matplotlib.pyplot as plt
x, y = np.loadtxt ("condensed.txt", usecols=(1, 2),        
delimiter=",", unpack=True)
for ii in range (len(x)): x[ii].replace('.txt', '.lc\n') jd, npmag = np.loadtxt ("/net/jovan/export/jovan/oelkerrj/Vela/rotation/Vela/"+x[ii], usecols= (1, 2), unpack=True)
    plt.scatter (jd, npmag)
    plt.xlabel ('Time')
    plt.ylabel ('Mag')
    plt.ylim ([max (npmag), min (npmag)])
    plt.show() # aftertest comment this out
    fileName = x[ii][:-3] + ".png"
    plt.savefig(fileName)

print "done"

Top answer
1 of 2
2
Hi! I'm working on a bot to reply with suggestions for common python problems. This might not be very helpful to fix your underlying issue, but here's what I noticed about your submission: You are looping over an object using something like for x in range(len(items)): print(items[x]) This is simpler and less error prone written as for item in items: print(item) If you DO need the indexes of the items, use the enumerate function like for idx, item in enumerate(items): print(idx, item) If you think you need the indexes because you are doing this: for x in range(len(items)): print(items[x], prices[x]) Then you should be using zip: for item, price in zip(items, prices): print(item, price)
2 of 2
1
Numpy arrays are not the same as strings, so they don't have the normal string methods. However, there are function versions of most of the string methods you can use: x = np.replace(x, '.txt', '.lc') This had the advantage of operating on every element of the array at once, rather than having to do each one-at-a-time in a loop. So the above line would go before the loop, not inside it. To convert x[ii] to a normal string you can use the x[ii].tolist(). Despite what the name implies, tolist doesn't convert to a list for numpy scalars (which x[ii]) is, instead it converts to the appropriate native python type (so numpy ints to python integers, numpy floats to python floats, numpy strings to python strings, etc.). You can then use normal python string operations on the result.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-fix-numpy-float64-object-cannot-be-interpreted-as-an-integer
How to Fix: ‘numpy.float64’ object cannot be interpreted as an integer - GeeksforGeeks
December 19, 2021 - When a function or operation is applied to an object of the wrong type, a type error is raised. The 'numpy.float64' object cannot be interpreted as an integer is one example of this type of problem.
🌐
Archlinux
copyprogramming.com › t › attributeerror-float-object-has-no-attribute-isnumeric
Attributeerror Float Object Has No Attribute Isnumeric - CopyProgramming
: 'float' object has no attribute 'isnull' How to fix this?, : 'float' object has no attribute 'sin' (Pdb) θr.dtype dtype('O') (Pdb) np.sin(θr) *** AttributeError, : 'float' object has no attribute 'sin' (Pdb) θr.sin() *** AttributeError: 'Series' object has no attribute, 'sin' (Pdb) θr.values.sin() *** AttributeError: 'numpy.ndarray' object has no attribute 'sin' (Pdb), ) np.sin(arr) # AttributeError: 'float' object has no attribute 'sin' When
🌐
CopyProgramming
copyprogramming.com › howto › fixing-the-common-numpy-float64-object-has-no-attribute-isnull-error-in-python
Resolving the Widely Occurring Error in Python: 'isnull' is not an Attribute of 'numpy float64' Object - Numpy float64
April 7, 2023 - While working with NumPy arrays, accessing a single-element row that happens to be a float may lead to the "numpy float64 object has no attribute isnull " error. This error message can be frustrating to troubleshoot. Users may encounter various errors related to numpy.float64 objects, such as those encountered when using ‘apply’, ‘log10’, ‘index’, ‘last_node’, ‘lower’, ‘isnumeric’, ‘shift’, or ‘isnan’. Additionally, errors may occur when attempting to access attributes that are not defined for ’NoneType’ or ’numpy.int64’ objects.
Find elsewhere
🌐
IQCode
iqcode.com › code › python › numpyfloat64-object-has-no-attribute-isnull
'numpy.float64' object has no attribute 'isnull' Code Example
September 29, 2021 - numpy.float64' object has no attribute 'isNull' AttributeError: 'numpy.int64' object has no attribute 'isnull' 'numpy.float64' object has no attribute 'isna' 'numpy.float64' object has no attribute 'isnan' numpy.float64' object has no attribute 'isnan' AttributeError: 'numpy.float64' object has no attribute 'isnull' float' object has no attribute 'notnull' 'numpy.float64' object is not iterable AttributeError: 'numpy.float64' object has no attribute 'pct_change' 'numpy.float64' object has no attribute 'isin' 'numpy.float64' object has no attribute 'format' AttributeError: 'float' object has no
🌐
CopyProgramming
copyprogramming.com › howto › how-to-solve-numpy-float64-object-has-no-attribute-encode-in-python-3
Python: Resolving the 'encode' attribute error for 'numpy.float64' objects in Python 3
April 3, 2023 - The variable identified by varj cannot be converted to a numpy datatype anymore as it is of type numpy.float64 . To invert a matrix using to_numpy , it is recommended to apply it to the dataframe instead of the variable. Error: 'float' object has no attribute 'isna'", 1st try: for element in my_series: if element.isna (): print ('do A') else: print ('do B') When running it, I've got the error: "'float' object has no attribute 'isna'".
🌐
DaniWeb
daniweb.com › programming › software-development › code › 447842 › a-python-module-isnumeric
A Python module 'isnumeric' | DaniWeb
February 15, 2013 - ''' isnumeric.py test a numeric string s if it's usable for int(s) or float(s) ''' def isnumeric(s): '''returns True if string s is numeric''' return all(c in "0123456789.+-" for c in s) and any(c in "0123456789" for c in s) # test module ...
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
<string>.isnumeric() - Raspberry Pi Forums
Douglas6 wrote:isnumeric() seems to be a function of unicode objects, not strings. Since you are expecting an integer, I'd try the isdigit() function. Bets are off with Python 3, but you mentioned 2. [EDIT: Wrong. Python 2 will automatically convert integer inputs to integer data types.
🌐
Reddit
reddit.com › r/learnpython › [deleted by user]
AttributeError: 'numpy.float64' object has no attribute 'lower'
August 28, 2022 - Everything in a csv is a string. When you read it in to pandas or numpy etc they will assume a type sometimes. In your example it looks like the first 'column' of your data should be a number (float64 is a 64bit float number) if you parsed it as comma delimited.
🌐
GitHub
github.com › AI4Finance-Foundation › FinRL-Meta › issues › 227
'numpy.float64' object has no attribute 'values' · Issue #227 · AI4Finance-Foundation/FinRL-Meta
September 4, 2022 - AttributeError Traceback (most recent call last) [<ipython-input-103-4fbf8c9df76f>](https://localhost:8080/#) in <module> 12 13 ---> 14 cryptoEnv =cryptoPortfolioAllocationEnvironment(path=PATH, **envKwargs) 1 frames [<ipython-input-102-10be5fc69e51>](https://localhost:8080/#) in <listcomp>(.0) 39 self.frame = self.dataFrame.loc[self.dateIncriment, :] 40 self.covarianceList = self.frame['covarianceList'][0] ---> 41 self.stateVar = np.append(np.array(self.covarianceList),[self.frame[indic].values.tolist() for indic in self.indicatorList],axis=0) 42 #self.state = np.append(np.array(self.covs), [self.data[tech].values.tolist() for tech in self.tech_indicator_list ], axis=0) 43 AttributeError: 'numpy.float64' object has no attribute 'values'`
Author   Daiiszuki
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.char.isnumeric.html
numpy.char.isnumeric — NumPy v2.3 Manual
January 31, 2021 - char.isnumeric(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'isnumeric'>#
🌐
Reddit
reddit.com › r/dsp › 'numpy.float64' object cannot be interpreted as an integer
r/DSP on Reddit: 'numpy.float64' object cannot be interpreted as an integer
June 8, 2021 -

I am trying to do a spectral flux analysis of an .wav input signal and I am getting this error and I don't know how to fix it. The code is:

! The errors are fixed now and the solutions are added as comments. Thank you all for the help ^

import numpy as np

from numpy.lib import stride_tricks


def stft(sig, frameSize, overlapFac=0.5, window=np.hanning):
    from numpy.lib import stride_tricks
    win = window(frameSize)
    hopSize = int(frameSize - np.floor(overlapFac * frameSize))

    # zeros at beginning (thus center of 1st window should be for sample nr. 0)
    samples = np.append(np.zeros(np.floor(frameSize/2.0)), sig)
    #fix error:samples = np.append(np.zeros(int(np.floor(frameSize/2.0))), sig)
# cols for windowing
    #fix error:cols = int(np.ceil( (len(samples) - frameSize) /float(hopSize))+1)
    cols = np.ceil( (len(samples) - frameSize) / float(hopSize)) + 1
    # zeros at end (thus samples can be fully covered by frames)
    samples = np.append(samples, np.zeros(frameSize))

    frames = stride_tricks.as_strided(samples, shape=(cols, frameSize), strides=(samples.strides[0]*hopSize, samples.strides[0])).copy()
    frames *= win

    return np.fft.rfft(frames)

spectral flux function:

def spectral_Flux(wavedata, window_size, sample_rate):
    # convert to frequency domain
    magnitude_spectrum = stft(wavedata, window_size)
    timebins, freqbins = np.shape(magnitude_spectrum)

    # when do these blocks begin (time in seconds)?
    timestamps = (np.arange(0,timebins - 1) * (timebins / float(sample_rate)))

    sf = np.sqrt(np.sum(np.diff(np.abs(magnitude_spectrum))**2, axis=1)) / freqbins

    return sf[1:] #, np.asarray(timestamps)

the Error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-157-54c4d632ffbf> in <module>
----> 1 sFlux=spectral_Flux(data,512,fs)

<ipython-input-156-f14509755e4e> in spectral_Flux(wavedata, window_size, sample_rate)
      1 def spectral_Flux(wavedata, window_size, sample_rate):
      2     # convert to frequency domain
----> 3     magnitude_spectrum = stft(wavedata, window_size)
      4     timebins, freqbins = np.shape(magnitude_spectrum)
      5 

<ipython-input-155-b145f5690a25> in stft(sig, frameSize, overlapFac, window)
     11 
     12     # zeros at beginning (thus center of 1st window should be for sample nr. 0)
---> 13     samples = np.append(np.zeros(np.floor(frameSize/2.0)), sig)
     14     # cols for windowing
     15     cols = np.ceil( (len(samples) - frameSize) / float(hopSize)) + 1

TypeError: 'numpy.float64' object cannot be interpreted as an integer

The seccond error:

TypeError                                 Traceback (most recent call last)
<ipython-input-193-54c4d632ffbf> in <module>
----> 1 sFlux=spectral_Flux(data,512,fs)

<ipython-input-192-f14509755e4e> in spectral_Flux(wavedata, window_size, sample_rate)
      1 def spectral_Flux(wavedata, window_size, sample_rate):
      2     # convert to frequency domain
----> 3     magnitude_spectrum = stft(wavedata, window_size)
      4     timebins, freqbins = np.shape(magnitude_spectrum)
      5 

<ipython-input-191-0ee2f8ea37ed> in stft(sig, frameSize, overlapFac, window)
     17     samples = np.append(samples, np.zeros(frameSize))
     18 
---> 19     frames = stride_tricks.as_strided(samples, shape=(cols, frameSize), strides=(samples.strides[0]*hopSize, samples.strides[0])).copy()
     20     frames *= win
     21 

C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\stride_tricks.py in as_strided(x, shape, strides, subok, writeable)
     99         interface['strides'] = tuple(strides)
    100 
--> 101     array = np.asarray(DummyArray(interface, base=x))
    102     # The route via `__interface__` does not preserve structured
    103     # dtypes. Since dtype should remain unchanged, we set it explicitly.

C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\_asarray.py in asarray(a, dtype, order)
     81 
     82     """
---> 83     return array(a, dtype, copy=False, order=order)
     84 
     85 

TypeError: 'numpy.float64' object cannot be interpreted as an integer

Top answer
1 of 2
4

You are using the same variable name, du, for two distinct concepts (the container for all the valid du values, and each individual du value per iteration).

Change your code to du_values = [] and du_values.append(N[j + 1]) and it should work.

As an aside, there appears to be a typo in your code - you define the original array as NP, but later refer to it as N.

2 of 2
0

Note that since you did not provide any code, the code I am going to show you is not FOR you but code I have used and SOUNDS like you could easily adopt to to your needs.

 # this will simulate 1000 different combinations of my portfolio
    for x in range(1000):
        weights = np.random.random(len(tickers))
        weights /= np.sum(weights)
        portfolio_returns.append(np.sum(weights * log_returns.mean()) * 250)
        portfolio_volatilities.append(np.sqrt(np.dot(weights.T, np.dot(log_returns.cov() * 250, weights))))

What this code is doing is short is 1000x it is creating random numbers and weights for my data points, and then appending the result.The code won't be uniform as it is random, but if you really wanted uniform you could simply step through the increments. However I don't think you want uniform, but rather a large enough sample size to not have it be thrown off by outliers.

A way to compare the results would be something like this.

simple_return = (mydata / mydata.shift(1)) - 1

Comparing random samples should be pretty straightforard, so if you do need help follow up. And with numpy arrays you can also filter/remove items based on criteria.

Sorry if these do not answer exactly what you are wanting, but it should get you headed in the right direction.