Convert Figma logo to code with AI

pydata logopandas-datareader

Extract data from a wide range of Internet sources into a pandas DataFrame.

2,905
681
2,905
147

Top Related Projects

13,247

Download market data from Yahoo! Finance's API

A python wrapper for Alpha Vantage API for financial data.

17,609

Zipline, a Pythonic Algorithmic Trading Library

1,897

ffn - a financial function library for Python

1,316

ARCH models in Python

Quick Overview

Pandas-datareader is a Python library that extends the functionality of pandas to easily access various financial and economic data sources. It provides a unified interface to retrieve data from popular sources like Yahoo Finance, Google Finance, World Bank, and more, allowing users to seamlessly integrate financial data into their pandas workflows.

Pros

  • Easy integration with pandas DataFrames
  • Supports multiple data sources in a consistent manner
  • Simplifies the process of fetching financial and economic data
  • Regular updates to maintain compatibility with data sources

Cons

  • Some data sources may become unavailable or change their APIs
  • Limited to the specific data sources implemented in the library
  • May require additional dependencies for certain data sources
  • Performance can be affected by network connectivity and data source responsiveness

Code Examples

  1. Fetching stock data from Yahoo Finance:
import pandas_datareader as pdr

# Get Apple stock data for the last 5 years
apple_data = pdr.get_data_yahoo('AAPL', start='2018-01-01', end='2023-01-01')
print(apple_data.head())
  1. Retrieving currency exchange rates from the Federal Reserve:
import pandas_datareader.data as web

# Get USD to EUR exchange rate for the last month
usd_eur = web.DataReader('DEXUSEU', 'fred', start='2023-05-01', end='2023-06-01')
print(usd_eur.tail())
  1. Fetching World Bank indicators:
from pandas_datareader import wb

# Get GDP per capita for the United States and China
gdp_per_capita = wb.download(indicator='NY.GDP.PCAP.CD', country=['US', 'CN'], start=2010, end=2020)
print(gdp_per_capita)

Getting Started

To get started with pandas-datareader, follow these steps:

  1. Install the library using pip:

    pip install pandas-datareader
    
  2. Import the library in your Python script:

    import pandas_datareader as pdr
    
  3. Use the appropriate function to fetch data from your desired source:

    # Example: Get Google stock data for the last month
    google_data = pdr.get_data_yahoo('GOOGL', start='2023-05-01', end='2023-06-01')
    print(google_data.head())
    

That's it! You can now start exploring various financial and economic data sources using pandas-datareader.

Competitor Comparisons

13,247

Download market data from Yahoo! Finance's API

Pros of yfinance

  • More actively maintained and updated
  • Simpler API for fetching data
  • Supports more Yahoo Finance features (e.g., options data, company info)

Cons of yfinance

  • Limited to Yahoo Finance data only
  • May be less stable due to reliance on web scraping
  • Smaller community and less extensive documentation

Code Comparison

pandas-datareader:

import pandas_datareader as pdr
data = pdr.get_data_yahoo("AAPL", start="2020-01-01", end="2021-01-01")

yfinance:

import yfinance as yf
ticker = yf.Ticker("AAPL")
data = ticker.history(start="2020-01-01", end="2021-01-01")

Both libraries provide similar functionality for fetching historical stock data, but yfinance offers a more straightforward API. pandas-datareader supports multiple data sources, while yfinance is focused solely on Yahoo Finance. yfinance provides additional methods for accessing other types of financial data, such as company information and options data, which are not available in pandas-datareader.

A python wrapper for Alpha Vantage API for financial data.

Pros of alpha_vantage

  • Focused specifically on Alpha Vantage API, providing comprehensive coverage of its features
  • Offers both synchronous and asynchronous implementations
  • Includes built-in rate limiting to prevent API usage violations

Cons of alpha_vantage

  • Limited to a single data source (Alpha Vantage), while pandas-datareader supports multiple sources
  • May require more setup and configuration compared to pandas-datareader's simpler interface
  • Less integrated with the pandas ecosystem

Code Comparison

alpha_vantage:

from alpha_vantage.timeseries import TimeSeries
ts = TimeSeries(key='YOUR_API_KEY')
data, _ = ts.get_daily('MSFT')

pandas-datareader:

import pandas_datareader as pdr
data = pdr.get_data_yahoo('MSFT')

Both libraries provide methods to fetch financial data, but alpha_vantage requires an API key and offers more specific Alpha Vantage functionality, while pandas-datareader provides a simpler interface for multiple data sources.

17,609

Zipline, a Pythonic Algorithmic Trading Library

Pros of Zipline

  • Comprehensive backtesting engine for algorithmic trading strategies
  • Simulates realistic market conditions, including slippage and transaction costs
  • Integrates with Quantopian's research environment for seamless strategy development

Cons of Zipline

  • Steeper learning curve due to its complexity and specialized focus
  • Less frequently updated compared to Pandas-datareader
  • Requires more setup and configuration for standalone use

Code Comparison

Pandas-datareader:

import pandas_datareader as pdr
data = pdr.get_data_yahoo('AAPL', start='2020-01-01', end='2021-01-01')

Zipline:

from zipline.api import order, record, symbol
def initialize(context):
    context.asset = symbol('AAPL')
def handle_data(context, data):
    order(context.asset, 10)
    record(AAPL=data.current(context.asset, 'price'))

Key Differences

Pandas-datareader focuses on data retrieval from various sources, while Zipline is a full-fledged backtesting framework. Pandas-datareader is more suitable for general data analysis tasks, whereas Zipline is specifically designed for developing and testing trading algorithms. Zipline offers more realistic simulations but requires more specialized knowledge to use effectively.

1,897

ffn - a financial function library for Python

Pros of ffn

  • Offers a wider range of financial analysis tools and performance metrics
  • Includes portfolio optimization and risk analysis features
  • Provides built-in plotting functions for visualizing financial data

Cons of ffn

  • Less frequently updated compared to pandas-datareader
  • Smaller community and fewer contributors
  • More focused on financial analysis, less versatile for general data retrieval

Code Comparison

ffn:

import ffn

data = ffn.get('SPY, AAPL, MSFT', start='2010-01-01')
perf = data.calc_stats()
print(perf.display())

pandas-datareader:

import pandas_datareader as pdr

data = pdr.get_data_yahoo(['SPY', 'AAPL', 'MSFT'], start='2010-01-01')
print(data.head())

ffn focuses on financial analysis and performance metrics, while pandas-datareader is primarily used for data retrieval from various sources. ffn provides more advanced financial tools out of the box, but pandas-datareader offers greater flexibility in data sources and is more regularly maintained.

1,316

ARCH models in Python

Pros of arch

  • Specialized in econometric modeling, particularly ARCH and GARCH models
  • Offers advanced statistical tests and forecasting capabilities
  • Provides comprehensive documentation and examples for financial analysis

Cons of arch

  • More focused on specific econometric models, less general-purpose than pandas-datareader
  • Steeper learning curve for users not familiar with econometrics
  • May require additional dependencies for certain functionalities

Code Comparison

arch:

import arch
model = arch.arch_model(returns)
results = model.fit()
forecast = results.forecast()

pandas-datareader:

import pandas_datareader as pdr
data = pdr.get_data_yahoo('AAPL', start='2020-01-01', end='2021-12-31')
returns = data['Close'].pct_change().dropna()

arch focuses on modeling and forecasting volatility, while pandas-datareader is primarily used for data retrieval from various sources. The code examples demonstrate their different use cases: arch for econometric modeling and pandas-datareader for fetching financial data.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

pandas-datareader

Up to date remote data access for pandas, works for multiple versions of pandas.

image image image image License

Installation

Install using pip

pip install pandas-datareader

Usage

import pandas_datareader as pdr
pdr.get_data_fred('GS10')

Documentation

Stable documentation is available on github.io. A second copy of the stable documentation is hosted on read the docs for more details.

Development documentation is available for the latest changes in master.

Requirements

Using pandas datareader requires the following packages:

  • pandas>=1.5.3
  • lxml
  • requests>=2.19.0

Building the documentation additionally requires:

  • matplotlib
  • ipython
  • requests_cache
  • sphinx
  • pydata_sphinx_theme

Development and testing additionally requires:

  • black
  • coverage
  • codecov
  • coveralls
  • flake8
  • pytest
  • pytest-cov
  • wrapt

Install latest development version

python -m pip install git+https://github.com/pydata/pandas-datareader.git

or

git clone https://github.com/pydata/pandas-datareader.git
cd pandas-datareader
python setup.py install