Wrap in a class and set function as static

This commit is contained in:
2026-02-11 20:03:05 -08:00
parent cccf4650c2
commit 0fcdfc91bf
+5 -1
View File
@@ -1,6 +1,10 @@
import yfinance as yf import yfinance as yf
import pandas as pd import pandas as pd
class DataPuller:
@staticmethod
def pull():
# Import the S&P 500 symbols # Import the S&P 500 symbols
symbols = pd.read_excel("./data/stock_symbols.xlsx") symbols = pd.read_excel("./data/stock_symbols.xlsx")
symbols.columns = symbols.columns.str.strip() symbols.columns = symbols.columns.str.strip()
@@ -10,7 +14,7 @@ tickers = symbols['Symbol'].tolist()
all_data = [] all_data = []
for i, symbol in enumerate(tickers): # Try first 20 for i, symbol in enumerate(tickers): # Try first 20
print(f"Processing: {i} of {len(tickers)}") print(f"Processing: {i} of {len(tickers)}")
df = yf.download(symbol, period="max") df = yf.download(symbol, period="max", auto_adjust=True)
if not df.empty: if not df.empty:
# Remove the ticker column # Remove the ticker column
df.columns = df.columns.get_level_values(0) df.columns = df.columns.get_level_values(0)