Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why am I seeing "TypeError: string indices must be integers" in this situation?

im trying to predict stock market movement but in the start i’m stuck in this error: "TypeError: string indices must be integers"

the code that i have problem with is:

import pandas_datareader as web
df = web.DataReader('AAPL', data_source='yahoo', start='2012-01-01', end='2019-12-17')

TypeError: string indices must be integers

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The YahooDailyReader seems to be broken from pandas_datareader. However, you can use yfinance module directly:

import yfinance as yf

df = yf.download('AAPL', start='2012-01-01', end='2019-12-17')

Output:

>>> df
                 Open       High        Low      Close  Adj Close     Volume
Date                                                                        
2012-01-03  14.621429  14.732143  14.607143  14.686786  12.500194  302220800
2012-01-04  14.642857  14.810000  14.617143  14.765714  12.567368  260022000
2012-01-05  14.819643  14.948214  14.738214  14.929643  12.706892  271269600
2012-01-06  14.991786  15.098214  14.972143  15.085714  12.839728  318292800
2012-01-09  15.196429  15.276786  15.048214  15.061786  12.819361  394024400
...               ...        ...        ...        ...        ...        ...
2019-12-10  67.150002  67.517502  66.464996  67.120003  65.655716   90420400
2019-12-11  67.202499  67.775002  67.125000  67.692497  66.215721   78756800
2019-12-12  66.945000  68.139999  66.830002  67.864998  66.384460  137310400
2019-12-13  67.864998  68.824997  67.732498  68.787498  67.286835  133587600
2019-12-16  69.250000  70.197502  69.245003  69.964996  68.438629  128186000

[2002 rows x 6 columns]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading