I'm working on a personal project - more of a learning venture than anything and the project consists of a few what may seem common tasks for data wrangling in python. I've tried multiple avenues to solve on my own or with information gleaned form other threads, but no luck just yet.
Some background: I'm trying to take a list or dataframe of stock tickers and pass into the ticker module of yfinance to pull history for a large list of stocks. Sounds simple - and probably is for someone who's lived with Python for a while.
My script:
import yfinance as yf
import pandas as pd
from get_all_tickers import get_tickers as gt
list_of_tickers = gt.get_tickers()
tickerlist = pd.DataFrame(list_of_tickers, columns = ["Ticker"])
tickerlist = tickerlist.values.tolist()
tc = ""
for x in tickerlist:
tc += str(x)
tc = tc.replace(" ", "")
tc = tc.replace("[", ",")
tc = tc.replace("]", "")
tc = tc.replace("'", "")
#tc = ",".join(tc)
def Convert(string):
li = list(string.split(","))
return li
tc = Convert(tc)
df = pd.DataFrame(data=tc, columns = ["Ticker"])
df_filtered = df.iloc[1: , : ]
#df_filtered.update('"' + df_filtered[['Ticker']].astype(str) + '"')
# df_filtered.to_csv("./StockTickers.csv", sep=',',index=False)
list_filtered = df_filtered.values.tolist()
# valid periods: 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max
period= "1d"
# valid intervals: 1m,2m,5m,15m,30m,60m,90m,1h,1d,5d,1wk,1mo,3mo
interval = "1d"
#=============================================================================
for ticker in df_filtered: #df_filtered.iterrows():
ticker = str(ticker).upper()
ticker = yf.Ticker("DDD")
history = ticker.history(
period = period,
interval = interval
)
print(history)
print(df_filtered)