VOOZH about

URL: https://www.geeksforgeeks.org/python/get-financial-data-from-yahoo-finance-with-python/

⇱ Get Financial Data from Yahoo Finance with Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Get Financial Data from Yahoo Finance with Python

Last Updated : 23 Jul, 2025

Yahoo Finance provides access to financial data which including stock prices, company financials and key metrics. By using the yfinance Python library we can easily retrieve this data and analyze it for various financial tasks. In this article, we'll see how to use Python to get financial data from Yahoo Finance and display it in a structured format.

Before we start we need to install the yfinance library. We can install it by using pip command:

pip install yfinance

For fetching financial data, we need the ticker symbol of the company. A ticker is a unique series of letters assigned to a security for trading purposes. For example:

  1. For Amazon, it is "AMZN"
  2. For Meta, it is "META"
  3. For Google, it is "GOOGL"

Below are various examples that shows how to retrieve Financial Data from Yahoo Finance. Let us take the results for Meta hence we use the "META" ticker.

Example 1: Getting Meta (Facebook) Financial Information

Getting basic financial information about Meta we can use .info() function.

Output:

{'address1': '1 Meta Way', 'city': 'Menlo Park', 'state': 'CA', 'zip': '94025', 'country': 'United States',-------'trailingPegRatio': 0.7646}

Example 2: Getting META Financial metrics

We can fetch financial key metrics like Company Sector, Price Earnings Ratio and Company Beta from the above dictionary of items quickly.

Output :

Company Sector: Communication Services
P/E Ratio: 20.967308
Company Beta: 1.279

Example 3: Getting META information in key-value pairs

Though we have fetched few financial key metrics in a dictionary format we can split that by using key-value pair. 

Output :

πŸ‘ finance1
META information in key-value pairs

Example 4: Getting META Historic Data

To get the historical market data such as stock prices we can use the history() method. Fetching Meta’s stock prices for the maximum available period and displaying it in a tablular format.

Output :

πŸ‘ finance22
META historic data

Example 5: Getting all the rows of META historical data

If we want to display all the rows of a ticker symbol we will use Pandas function and set the set_option() function to display maximum rows.

Output:

πŸ‘ finance3
META historic data for all rows

Example 6: Getting Historical Data for a Specific Period

We can specify a custom date range to fetch historical data. Here’s we used for Meta to get information from May 31, 2019 to January 30, 2021.

Output:

πŸ‘ finance4
META information from 2019/05/31

Example 7: Visualize Data and Display in Tabular Format

We can visualize the closing prices using matplotlib library.

Output:

πŸ‘ finance5
META history of 1 year
πŸ‘ finance55
META Stock data

Whether we are tracking stock prices, analyzing market trends or finding company financials these methods will provide us flexibility and tools need to perform in-depth analysis and valuable insights.

Comment
Article Tags: