Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'DataFrame' object has no attribute 'set_value' #7

Open
akitxu opened this issue Apr 16, 2022 · 1 comment
Open

AttributeError: 'DataFrame' object has no attribute 'set_value' #7

akitxu opened this issue Apr 16, 2022 · 1 comment

Comments

@akitxu
Copy link

akitxu commented Apr 16, 2022

Thanks for sharing this work. I try to understand it by running some sscripts. In the script for calculating the 'Accumulation Distribution', it returns the error that I mention in the title.

`import pandas as pd
import yfinance as yf

Accumulation Distribution

def acc_dist(data, trend_periods=21, open_col='Open', high_col='High', low_col='Low', close_col='Close', vol_col='Volume'):
for index, row in data.iterrows():
if row[high_col] != row[low_col]:
ac = ((row[close_col] - row[low_col]) - (row[high_col] - row[close_col])) / (row[high_col] - row[low_col]) * row[vol_col]
else:
ac = 0
data.set_value(index, 'acc_dist', ac)
data['acc_dist_ema' + str(trend_periods)] = data['acc_dist'].ewm(ignore_na=False, min_periods=0, com=trend_periods, adjust=True).mean()

return data

n = 14
data = df = yf.download('AAPL', start= start_day, end = end_day)
data = acc_dist(df_val, trend_periods=21, open_col='Open>', high_col='High', low_col='Low', close_col=nom_val, vol_col='Volume')

`
Me devuelve,

`[100%**] 1 of 1 completed


AttributeError Traceback (most recent call last)
/tmp/ipykernel_2963/3008653052.py in
33
34 data = df = yf.download('AAPL', start= start_day, end = end_day)
---> 35 data = acc_dist(df_val, trend_periods=21, open_col='Open>', high_col='High', low_col='Low', close_col=nom_val, vol_col='Volume')
36

/tmp/ipykernel_2963/3008653052.py in acc_dist(data, trend_periods, open_col, high_col, low_col, close_col, vol_col)
27 else:
28 ac = 0
---> 29 data.set_value(index, 'acc_dist', ac)
30 data['acc_dist_ema' + str(trend_periods)] = data['acc_dist'].ewm(ignore_na=False, min_periods=0, com=trend_periods, adjust=True).mean()
31

~/anaconda3/envs/yfinance/lib/python3.9/site-packages/pandas/core/generic.py in getattr(self, name)
5485 ):
5486 return self[name]
-> 5487 return object.getattribute(self, name)
5488
5489 def setattr(self, name: str, value) -> None:

AttributeError: 'DataFrame' object has no attribute 'set_value'`

What can be the cause?

@akitxu
Copy link
Author

akitxu commented Apr 17, 2022

It works by making the following change
data.loc[index, 'acc_dist' ] = ac #data.set_value(index, 'acc_dist', ac) # pone un unico valor en la columna y el índice que se pasan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant