Search code examples
pythonpython-3.xyahoo-financeyfinance

Is it possible to get just the price from a specific day?


This is what I have done so far:

import yfinance as yf
import pandas as pd
print(yf.download("META", start="2023-08-14", end="2023-08-15")['Adj Close'])

Output:
Date
2023-08-14    306.190002
Name: Adj Close, dtype: float64

I was hoping to just get the price from the specific day 14/8/23 but I get some other information. Is there an alternative approach that I can use to get just the price from a specific day? Thanks


Solution

  • this should work!

    x= yf.download("META", start="2023-08-14", end="2023-08-15")['Adj Close'][0]
    

    also if you would have only one row always in x variable, you can use iloc

    data=yf.download("META", start="2023-08-14", end="2023-08-15")
    x=data.iloc[0]['Adj Close']
    

    enter image description here