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

MOEX: AttributeError: 'DataFrame' object has no attribute 'append' #991

Open
RJSDevel opened this issue May 27, 2024 · 1 comment
Open

Comments

@RJSDevel
Copy link

import pandas_datareader as pdr

df = pdr.get_data_moex('SBER', start='2024-05-26')
df.head()

AttributeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_18664\2461240623.py in ?()
1 import pandas_datareader as pdr
2 import pandas_montecarlo
3
----> 4 df = pdr.get_data_moex('SBER', start='2024-05-26')
5 df.head()

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas_datareader\data.py in ?(*args, **kwargs)
103 def get_data_moex(*args, **kwargs):
--> 104 return MoexReader(*args, **kwargs).read()

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas_datareader\moex.py in ?(self)
211 b = self.read_all_boards()
212 result = pd.DataFrame()
213 for secid in list(set(b["SECID"].tolist())):
214 part = b[b["BOARDID"] == boards[secid]]
--> 215 result = result.append(part)
216 result = result.drop_duplicates()
217 return result

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\generic.py in ?(self, name)
6295 and name not in self._accessors
6296 and self._info_axis._can_hold_identifiers_and_holds_name(name)
6297 ):
6298 return self[name]
-> 6299 return object.getattribute(self, name)

AttributeError: 'DataFrame' object has no attribute 'append'

@dd-tar
Copy link

dd-tar commented Aug 11, 2024

@RJSDevel
I encountered the same problem.

This is happening because, as of pandas 2.0, the append method (which was previously deprecated) has been removed. We need to use concat instead. For more information, see this stackoverflow question.

UPD:
It turns out that the issue has already been fixed in the main branch, so the best solution would be to install the latest development version
(or manually replace the code in your local moex.py file with that from the main branch's moex.py).

The first solution was:

  1. Open the file ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas_datareader\moex.py

  2. Find line 215.
    It should look like this:
    result = result.append(part)

  3. Replace append() with concat(). That is, replace line 215 with the following:
    result = pd.concat([result, pd.DataFrame(part)], ignore_index=True)

  4. Save the changes and restart the kernel, then re-import the libraries.

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

2 participants