Aug-01-2022, 06:08 PM
Hi DustinKlent,
Try the following code.
Best,
Paul
Try the following code.
Best,
Paul
import glob import numpy as np import pandas as pd from yahoo_fin import stock_info as si # def getData2(tickers,type=1): stats_val = {} n=len(tickers) for i in range(0,n): ticker=tickers.ticker[i] if type==1: data= si.get_stats_valuation(ticker) else: data= si.get_stats(ticker) data = data.iloc[:,:2] data.columns = ["Attribute", "Recent"] stats_val[ticker] = data combined = pd.concat(stats_val) combined = combined.reset_index() del combined["level_1"] combined.columns = ["Ticker", "Attribute", "Recent"] df = pd.DataFrame(combined) df2 = df.drop_duplicates(subset=None, keep="first", inplace=False) return df2 # infile='http://datayyy.com/robo/tickers.txt' tickers=pd.read_table(infile) df=getData2(tickers) df2=getData2(tickers,2) np.shape(df) #Out[1194]: (36, 3) np.shape(df2) # Out[1195]: (204, 3) """ input file ticker aapl msft WMT IBM df.head() Out[1197]: Ticker Attribute Recent 0 aapl Market Cap (intraday) 2.61T 1 aapl Enterprise Value 2.68T 2 aapl Trailing P/E 26.86 3 aapl Forward P/E 25.45 4 aapl PEG Ratio (5 yr expected) 2.81 ""