从pandas数据读取器加载雅虎财务数据



为了在Python中分析苹果股票数据,我尝试使用Pandas数据读取器和Yahoo!资金为了做到这一点,在导入pandas数据读取器后,我尝试运行以下代码行:

import yfinance as yf
yf.override()
AAPL.df = pdr.data.get_data_yahoo('AAPL', start=start)[Adj Close].resample('M').ffill().pct_change()

在这样做之后,我得到了这个错误消息:

OverflowError                             Traceback (most recent call last)
c:UsersfolderFama-French.ipynb Cella 11 in <cell line: 2>()
----> 1 AAPL_df = pdr.DataReader(name='AAPL', start=start, data_source='yahoo')
2 AAPL_df.pct_change()
File ~AppDataLocalPackagesPythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0LocalCachelocal-packagesPython310site-packagespandasutil_decorators.py:207, in deprecate_kwarg.<locals>._deprecate_kwarg.<locals>.wrapper(*args, **kwargs)
205     else:
206         kwargs[new_arg_name] = new_arg_value
--> 207 return func(*args, **kwargs)
File ~AppDataLocalPackagesPythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0LocalCachelocal-packagesPython310site-packagespandas_datareaderdata.py:379, in DataReader(name, data_source, start, end, retry_count, pause, session, api_key)
367     raise NotImplementedError(msg)
369 if data_source == "yahoo":
370     return YahooDailyReader(
371         symbols=name,
372         start=start,
373         end=end,
374         adjust_price=False,
375         chunksize=25,
376         retry_count=retry_count,
377         pause=pause,
378         session=session,
--> 379     ).read()
...
--> 126     unix_start = int(time.mktime(self.start.timetuple()))
127     unix_start += four_hours_in_seconds
128     day_end = self.end.replace(hour=23, minute=59, second=59)
OverflowError: mktime argument out of range

发生了什么?最重要的是,我该怎么办?提前感谢

我认为你可以通过检查作者在他的github或PyPI中写了什么来解决这个问题。显然,你想用融资包来覆盖它。

from pandas_datareader import data as pdr
import yfinance as yf
yf.pdr_override()
AAPL_df= pdr.get_data_yahoo('AAPL')['Adj Close'].resample('M').ffill().pct_change()
[*********************100%***********************]  1 of 1 completed
AAPL_df
Out[8]: 
Date
1980-12-31         NaN
1981-01-31   -0.172163
1981-02-28   -0.061943
1981-03-31   -0.075475
1981-04-30    0.158163

2022-03-31    0.057473
2022-04-30   -0.097131
2022-05-31   -0.054496
2022-06-30   -0.081430
2022-07-31    0.188634
Freq: M, Name: Adj Close, Length: 500, dtype: float64

最新更新