pandas-datareader is a Python library that makes financial and economic data easily accessible, acting as an extension package to pandas. It initially existed as the pandas.io.data module and provided the ability to pull data from Yahoo Finance, Federal Reserve Economic Data (FRED), Google Finance, and more. I’ve noticed that Yahoo sometimes doesn’t work properly, so I’m guessing there’s a version mismatch with the example code.

pandas 0.19.0에서 분리 (2016년 10월)pandas.io.data 모듈이 공식적으로 deprecated 되고, 별도의 패키지인 Separated in pandas 0.19.0 (October 2016)The pandas.io.data module was officially deprecated and separated into a separate package, pandas-datareader. This was done for the following reasons

  • Minimizing dependencies: We wanted to remove code related to external API communication in order to focus on the core functionality of pandas.
  • Flexible maintenance: We separated it as an independent package to quickly respond to API changes in data sources (e.g., Yahoo Finance API deprecation).
  • Extensibility: We improved the structure to make it easier to add new data sources (Alpha Vantage, Quandl, etc.).

Since the separation, pandas-datareader is versioned separately from pandas and is actively maintained by the open source community. It is constantly being updated to keep up with changes in data sources (e.g. API key requirements, endpoint changes).

Purpose of development

  • Unified data access interface
    • Financial/economic data is distributed across many different sources, including Yahoo, FRED, and the World Bank. pandas-datareacher provides a consistent API to these sources, allowing users to easily retrieve data into DataFrames without having to write different code for each source.
  • Ease of research and analysis
    • Developed to simplify repetitive data collection tasks in financial data analysis, machine learning modeling, economic research, and more. For example, you can retrieve stock price or GDP data with just a few lines of code.
  • Responding to API changes
    • The community collaborates to provide solutions to flexibly respond to changes in external service policies, such as Yahoo Finance’s historic API outage (2017) and Alpha Vantage’s introduction of API keys.

Key data sources

  • Financial data: Yahoo Finance, Alpha Vantage, IEX Cloud
  • Economic indicators: FRED (US Federal Reserve), World Bank, OECD
  • Others: Nasdaq Trader, Tiingo, Quandl (paid), etc.

Packege install

pip install pandas-datareader

Naver Data 

import pandas_datareader.data as web

def get_pandas_naver_data(id, start, end):
    _df = web.DataReader(id, "naver", start=start, end=end)
    return _df

Stooq Data

import pandas_datareader.data as web

def get_pandas_stooq_data(id, start, end):
    _df = web.DataReader(id, "stooq", start=start, end=end)
    return _df

Fred Data

import pandas_datareader.data as web

def get_pandas_fred_data(id):
    return web.get_data_fred(id)

Output Main Code

import datetime as dt


if "__main__" == __name__:
    df = get_pandas_naver_data('005930', '2025-01-01', '2025-01-20')
    print(df.head())

    start_date = dt.datetime(2025, 1, 1)
    end_date = dt.datetime(2025, 1, 20)

    df = get_pandas_stooq_data('AAPL', start_date, end_date)
    print(df.head())

    df = get_pandas_fred_data("UNRATE")
    print(df.head())

By Mark

-_-

Leave a Reply

Your email address will not be published. Required fields are marked *