Yfinance 只打印一只股票的价格

Yfiance print only the price of a stock

我只想从 yfinance 打印股票价格,这就是我现在 get/have :

    ticker = "aapl"
    start = datetime.now().strftime('%Y-%m-%d')
    end = datetime.now().strftime('%Y-%m-%d')
    data = pdr.get_data_yahoo(ticker, start, end)
    data['EMA10'] = data['Close'].ewm(span=10, adjust=False).mean()
    print(data['EMA10'])

这是回复:

Date
2022-03-04    163.169998
Name: EMA10, dtype: float64

我只想打印 163....

你获得一个pd.Series。要 select 该系列中的 top-most 值只需执行 data['EMA10'][0].

完整代码如下:

from datetime import datetime
import pandas_datareader as pdr

ticker = "AAPL"
start = datetime.now().strftime('%Y-%m-%d')
end = datetime.now().strftime('%Y-%m-%d')
data = pdr.get_data_yahoo(ticker, start, end)
data['EMA10'] = data['Close'].ewm(span=10, adjust=False).mean()

print(data['EMA10'][0])

输出:

163.1699981689453