只是在寻找一个返回,在那里我可以输入股票代码并接收完整的公司名称列表:
list = ['MSFT','HIVE','etc','etc']
ticker(list)
将返回公司名称列表
你可以试试:
import yfinance as yf
ticker_list = ['MSFT','HIVE', "AAPL", "HOOD", "TSLA", "GOOG"]
def ticker(ticker_list):
com_name = []
for ticker in ticker_list:
stock = yf.Ticker(ticker)
name = stock.info.get('longName')
com_name.append(name)
return com_name
com_name_list = ticker(ticker_list)
print(com_name_list)
输出:
['Microsoft Corporation', 'HIVE Blockchain Technologies Ltd.', 'Apple Inc.', 'Robinhood Markets, Inc.', 'Tesla, Inc.', 'Alphabet Inc.']
您必须安装
yfinance
才能运行此代码。
yfinance安装命令:pip install yfinance