In this short tutorial, we’ll see how to check dividend history in Python using reliable financial data sources and popular libraries like pandas and yfinance. If you're building a dividend tracker, backtesting a strategy, or analyzing income stocks, retrieving historical dividend data programmatically is essential.
We’ll cover:
- How to download dividend history
- How to convert dividends into a clean pandas DataFrame
- How to calculate total and annual dividend income
1. Install Required Libraries
First, install the required packages:
pip install yfinance pandas
We’ll use:
- yfinance → to download dividend data
- pandas → to analyze and manipulate the data
2. Download Dividend History in Python
The easiest way to check dividend history is by using yfinance.
Example 1: Get Dividend History for a Stock
import yfinance as yf
import pandas as pd
# Choose stock ticker
ticker = "AAPL"
# Download ticker data
stock = yf.Ticker(ticker)
# Get dividend history
dividends = stock.dividends
# Convert to DataFrame
df_dividends = dividends.to_frame(name="Dividend")
print(df_dividends.head())
Output:
- Index → Dividend payment dates
- Column → Dividend amount per share
This gives you a complete dividend payment history for the selected stock.
3. Calculate Total Dividend Income
Now let’s calculate total dividend income over time.
Example 2: Calculate Total and Annual Dividends
# Reset index for easier manipulation
df_dividends = df_dividends.reset_index()
# Extract year
df_dividends["Year"] = df_dividends["Date"].dt.year
# Total dividend paid
total_dividends = df_dividends["Dividend"].sum()
# Annual dividends
annual_dividends = df_dividends.groupby("Year")["Dividend"].sum()
print("Total Dividends:", total_dividends)
print("\nAnnual Dividends:")
print(annual_dividends)
What this does:
- Groups dividends by year
- Calculates total dividend per year
- Helps analyze dividend growth trends
4. Practical Use Cases
Checking dividend history in Python is useful for:
- Dividend growth investing analysis
- Passive income forecasting
- Backtesting dividend reinvestment strategies
- Screening dividend-paying stocks
5. Bonus: Calculate Dividend Yield Over Time
You can also combine historical price data with dividends:
price_data = stock.history(period="5y")
latest_price = price_data["Close"].iloc[-1]
latest_dividend = annual_dividends.iloc[-1]
dividend_yield = latest_dividend / latest_price
print("Latest Dividend Yield:", dividend_yield)
This helps estimate current dividend yield based on historical payments.
6. Bonus: Useful sites
Recently Nasdaq seems to change and now I get message:
"Dividend History for Non-Nasdaq symbols is not available"
When I try to get the divident history from the site and the API - https://api.nasdaq.com/api/quote/SHEL/dividends.
Alternative sites for dividents:
Summary
In this short guide, we showed how to:
- Download dividend history in Python
- Convert dividends into a pandas DataFrame
- Calculate total and annual dividend income
- Estimate dividend yield
Using Python for dividend analysis allows you to automate income tracking and build advanced investing tools.