Streamlit app: not populating yfinance data when launching app, why?

Summary

When using yfinance Ticker.fast_into[“market_cap”] the data populates on my local machine, however, the data does not populate when hosting and launching the app on streamlit cloud.

I’m thinking the issue may be related to the version of yfinance used on both the local machine and server. My requirements.txt file hosted on github includes the proper version of yfinance.
Additionally, is the data source blocked or restricted by any firewall or security measures on the server hosting the Streamlit app?

Anything feedback would be greatly appreciated.

Steps to reproduce

**Code snippet: **

bond_etfs = ['AGG','HYG','LQD',"TLT","SHY","IEF",]
market_cap_df = pd.DataFrame(columns=["ETF","Market Cap"]
for etf in bond_etfs:
    etf_info = yf.Ticker(etf)
    market_cap = etf_info.fast_info["market_cap"]
    market_cap_df = market_cap_df.append({"ETF": etf, "Market Cap": market_cap}, 
    ignore_index=True)
st.dataframe(market_cap_df)

Expected behavior:

Expected for the data to be extracted, stored a new dataframe asnd populated on my application.
Below is a screenshot of whats happening on my local machine:
local machine

Actual behavior:
The data is not extracted, stored nor populated on my application.
Below is a screenshot of whats happening once my app is launched on the streamlit cloud server:
streamlit server

Debug info

  • Streamlit version: 1.17.0
  • Python version: 3.10
  • Using Conda
  • OS version: Catalina
  • Browser version: Chrome

Requirements file

streamlit==1.17.0
streamlit-option-menu==0.3.2
requests==2.27.1
babel==2.10.1
Pillow==9.1.1
sklearn==0.0
pycoingecko==2.2.0
pandas==1.3.5
numpy==1.21.6
plotly-express==0.4.1
statsmodels==0.13.2
openpyxl==3.0.10
yfinance==0.2.9

Links

Additional information

Hi @guy_gnakpa ,

I suggest doing some debugging on your app by yourself. I suggest checking that the yfinance module is loaded, then from there maybe printing out what is in the dataframe, and then if that doesn’t help, try digging into the yfinance module that is loaded.

William

Hi William,
thank you so much for taking the time to suggest a solution. I’ve been able to solve the issue by using pandas-datareader instead of yfinance. The data is displayed as intended.

WOO! Happy to hear that!

Great job and happy streamlitting :slight_smile:

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.