📜  pandas_datareader - Python (1)

📅  最后修改于: 2023-12-03 15:18:15.848000             🧑  作者: Mango

pandas_datareader - Python

pandas_datareader is a Python library for fetching financial data. It allows you to retrieve data from various sources like Yahoo Finance, Google Finance, Federal Reserve Economic Data (FRED), and more. pandas_datareader makes it easy to analyze and manipulate financial data right in a Python environment.

Installation

You can install pandas_datareader using pip:

pip install pandas-datareader
Usage

Here's an example of how to use pandas_datareader to fetch the daily closing price for Apple stock between January 1st, 2015 and December 31st, 2019:

import pandas_datareader.data as web
import datetime

start = datetime.datetime(2015, 1, 1)
end = datetime.datetime(2019, 12, 31)

df = web.DataReader('AAPL', 'yahoo', start, end)
print(df['Close'])

This will output:

Date
2015-01-02     27.332500
2015-01-05     26.562500
2015-01-06     26.565001
2015-01-07     26.937500
2015-01-08     27.972500
                 ...    
2019-12-24    284.269989
2019-12-26    289.910004
2019-12-27    289.799988
2019-12-30    291.519989
2019-12-31    293.649994
Name: Close, Length: 1258, dtype: float64
Supported sources

pandas_datareader supports the following sources:

  • Yahoo Finance
  • Google Finance
  • Morningstar
  • Federal Reserve Economic Data (FRED)
  • World Bank
  • OECD
  • Eurostat
  • IEX Cloud
  • Alpha Vantage
Conclusion

pandas_datareader is a great Python library for fetching and analyzing financial data. With support for various data sources and easy-to-use API, it makes it much easier to work with financial data in Python.