金融隔离股价

2024-09-22 16:09:11 发布

您现在位置:Python中文网/ 问答频道 /正文

G'day我只是想知道如何通过python使用yfinance模块分离股票价格,然后将该价格存储为变量,任何帮助都将不胜感激

import yfinance as yf

ticker = 'MSFT'
tickerData = yf.Ticker(ticker)

#get the historical prices for this ticker
tickerDf = tickerData.history(period='1d')

#see your data
tickerDf

这是可行的,但我最终得到的结果是,我试图隔离和存储价格的各种尝试(最后)都失败了。 output

非常感谢您的帮助


Tags: 模块theimportgetas价格tickerday
1条回答
网友
1楼 · 发布于 2024-09-22 16:09:11

如果要在单独的数据框“close_df”中隔离DateClose列,可以使用:

close_df=tickerDf[['Date','Close']]
close_df.set_index('Date')

并且,如果您希望在“closed_values_list”列表中使用Close值,请使用

closed_values_list= list(tickerDf['Close'])

相关问题 更多 >