使用pandas_datareader调用Yahoo接口获取数据遇弃用错误求助
Hey there! That error you're hitting is super common right now—Yahoo made major changes to their financial API that completely broke the pandas_datareader Yahoo connector, and there’s no stable replacement built into the library at the moment.
Luckily, there’s a straightforward workaround using the yfinance library, which was specifically built to fill this gap. Here’s how to fix your code:
Step 1: Install yfinance
First, install the library via pip if you haven’t already:
pip install yfinance
Step 2: Update Your Code
Replace your existing pandas_datareader import and data-fetching code with this:
import numpy as np import datetime import pandas as pd import yfinance as yf start = datetime.datetime(2017, 1, 1) end = datetime.datetime(2017, 12, 31) AAPL = yf.download('AAPL', start=start, end=end)
Why This Works
yfinance maintains an up-to-date connection to Yahoo’s financial data endpoints, and it returns data in the exact same pandas DataFrame format that pandas_datareader used. That means you can keep using all your existing data-processing code without major tweaks.
If you were set on using pandas_datareader directly, note that the project maintainers have said they welcome pull requests to re-enable the Yahoo connector—but there’s no timeline for a fix. So yfinance is the most reliable option right now.
内容的提问来源于stack exchange,提问作者Namish Mishra

