Skip to content
Advertisement

getting Market cap data using Yfinance

I was trying to get market cap data of stocks using yfinance. Here is my code:

JavaScript

By using this code I get the following error:

*** IndexError: list index out of range

I attach screenshots of the error and also of the DataFrame

Error

Tickers DataFrame

I referred to the url as specified below as to circumvent this issue.

Yfinance IndexError: list index out of range

The modified code made using the fix given in the above url is:

JavaScript

By using the above code I am getting an error as described in the screenshot:

By using the code I am getting the following error:

KeyError: ‘regularMarketPrice

The screenshot of the same is as shown:

Error

On clicking on the file which is mentioned in error we can see that the error is caused by the function def_read_lines. The screenshot is attached below:

Functions where error occours

I did try using the yahooquery library but in the values dataframe all the values are populated as error values and not the actual market cap values as shown:

values dataframe

I am not understanding where am I going wrong. Any help will be appreciated

Advertisement

Answer

It could be that some of the ticker in your excel file aren’t listed or there is some kind of naming issue. So i solved using try to download the stocks one by one with data.get_qoute_yahoo('ticker') and then with pd.concat() I obtained my dataframe.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement