Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Yfiance print only the price of a stock

I want to print only the price for a stock form yfinance, this is what I get/have now :

    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'])

and this is the response :

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

I only want to print 163….

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You obtain a pd.Series. To select the top-most value within that series just do data['EMA10'][0].

The entire code is given below:

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])

Output:

163.1699981689453

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading