import yfinance as yf
from datetime import datetime, timedelta
from pandas import DataFrame
startDate = datetime.now ()- timedelta(100)
endday = datetime.now()-timedelta(-1)
stockNo = xxx # xxx1, xxx2, ...stock code
start = startDate, end = endday
stock = yf.Ticker(stockNo)
stock_df = pd.DataFrame(stock.history(start = startDate, end = endday ))
f财务响应如下,我如何将此信息保存为列表或数据帧
- xxx1:未找到数据,符号可能会被摘牌
- xxx2:未找到数据,符号可能会被摘牌
这是一个非常晚的答案,但考虑到还没有:
import yfinance as yf
import pandas as pd
ticker = "ENTER_YOUR_TICKER_HERE"
yahootickerdata = yf.Ticker(f"{ticker}")
# this is already a dataframe so no need to read it in as one
# but this depends on what you're requesting from yfinance
earnings = yahootickerdata.earnings
# save to CSV
earnings.to_csv(f"data/{ticker}-yahoo-earnings.csv")
# and next time you can just load the CSV
df = pd.read_csv(f"data/{ticker}-yahoo-earnings.csv")