The Yfinance Python Library
The Yfinance Python Library
This example shows code for using yfinance to download historical stock prices.
1. 1
2. 2
3. 3
4. 4
5. 5
6. 6
7. 7
8. 8
1. import yfinance as yf
2.
3. # Download historical data for a stock
4. msft = yf.Ticker("MSFT")
5. msft_data = msft.history(period="max")
6.
7. # Display the downloaded data
8. msft_data.head()
Copied!
Here are some of the possible values for the period parameter and what they represent:
Finally, you print the downloaded data using the head function. This downloaded data will display a Pandas
data frame containing Microsoft's historical stock prices and other financial data.
about:blank 1/2
21/06/2024, 13:03 about:blank
Author(s)
Pooja Patel
Change Log
about:blank 2/2