Feb-11-2021, 11:24 AM
(This post was last modified: Feb-11-2021, 11:24 AM by detlefschmitt.)
I noticed that the yahoo_fin script below from DustinKlent returns an error if a stock ticker is in the stock_list that is not in the yahoo_fin stock_info. To avoid error messages I would like to compare the list of stocks in yahoo_fin stock_info with my stock list in Excel before I run the below script. To be able to do this I need to export to csv all stock tickers in the yahoo_fin stock_info. Is that possible with Yahoo_fin? If yes, how? Please post the script.
import pandas as pd from yahoo_fin import stock_info as si import glob stock_list = "ABEO", "ABUS" stats = {} for ticker in stock_list: data2 = si.get_stats(ticker) data2 = data2.iloc[:,:2] data2.columns = ["Attribute", "Recent"] stats[ticker] = data2 combined2 = pd.concat(stats) combined2 = combined2.reset_index() del combined2["level_1"] combined2.columns = ["Ticker", "Attribute", "Recent"] df = pd.DataFrame(combined2) df2 = df.drop_duplicates(subset=None, keep="first", inplace=False) df2.to_csv(r'stats.csv')