pydata / pandas-datareader

Extract data from a wide range of Internet sources into a pandas DataFrame.
https://pydata.github.io/pandas-datareader/stable/index.html
Other
2.96k stars 682 forks source link

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

Open RJSDevel opened 6 months ago

RJSDevel commented 6 months ago
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 commented 3 months ago

@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.