Ethereum: AttributeError: ‘numpy.float64’ object has no attribute ‘rolling’

Ethereum RSI Calculation Question: Solution

The problem you experience is common when working with Python and Number financial data. In this article, we go through what the error message tells us and we offer an updated solution to calculate the relative resistance index (RSI) using the simple moving media (SMA).

problem: attributeerror: 'numpy.float64' the object has no attribute 'rolling'‘ ‘

When importing the director “Number”, it returns a number of numerical paintings as an object. In some cases, however

`Python

Imports Number as NP

Create a painting with a float64

Arr = np.float64 (10)

The error message indicates that "Number.float64 does not have a” rolling “attribute. The reason for this is that the “rolling” method is part of the Pandas Library, which we will import later.

Solution: Pandas Calculate RSI -T

To calculate RSI, use the SMA and properly process the PANDAS director. Here is an updated detail of the code that shows the Calculation of the RSI:

`Python

Imports the panda as pd

Imports Number as NP

Function to calculate RSI with SMA

Depcade_rsi (data, short_window = 14, long_window = 26):

Calculate the simple movement media (SMA)

data ['sm'] = data ['closure']. Rolling (Window = short_window). Mean ()

Calculate relative (RSI) resistance index

Data ['rsi'] = 100.0 - (100.0 / (1 + data ['sm']. Pct_change (). Dropna ()) ** long_window)

return data

Loading of closing prices at Pandas Datoframe

DF = pd.read_csv ('stock_price.csv', index_col = 'data', pars_dates = ['data'])

Calculate RSI with SMA

RSI_DF = calculated_rsi (DF)

Print the first several lines of calculated RSI

Print (RSI_DF.Head ())

Explanation

In this updated code, we determine the function "calculated_rsi", which takes a Pandas Dataframe (data) and two parameters for short and long -moving media (short_window and long_window). Then calculate the SMA by “rolling” and then calculate the RSI by “PCT_CHANGE”. Finally, return RSI calculated as a new column in Pandas Dataframe.

Example use case

If you use this feature with your own data, simply replace the “Stock_price.csv’`” and “Data” positions with the file and data range you want. You can then use “calculated_rsi” to calculate RSI for shares.

I hope this will help! Announce it if you still have any further questions or questions.

Leave a Comment