打开雅虎金融历史图片

2024-10-03 02:45:57 发布

您现在位置:Python中文网/ 问答频道 /正文

使用我下载的雅虎财经,苹果的历史数据。我正在使用来自https://pypi.org/project/yahoofinancials/的信息

from yahoofinancials import YahooFinancials

ticker = 'AAPL'
yahoo_financials = YahooFinancials(ticker)

由此,我可以使用以下信息获取每周数据:

historical_price = yahoo_financials.get_historical_price_data('2020-01-05', '2021-01-05', 'weekly')

这很有效。但我正在努力把它打包成熊猫。很少有词典和词典列表让我感到困惑

电流输出为

                 AAPL
currency                                                      USD
eventsData                                                     {}
firstTradeDate  {'formatted_date': '1980-12-12', 'date': 34547...
instrumentType                                             EQUITY
prices          [{'date': 1609736400, 'high': 133.610000610351...
timeZone                                    {'gmtOffset': -18000} 

我的问题是,将上述内容解包成可用数据帧的最佳方法是什么


Tags: 数据苹果信息datepriceyahoo词典ticker
1条回答
网友
1楼 · 发布于 2024-10-03 02:45:57

我建议改用同样基于雅虎的yfinance

!pip install yfinance
import yfinance
yfinance.download('AAPL', start='2019-01-01', end='2020-12-31')

这将产生:

                  Open        High  ...   Adj Close     Volume
Date                                ...                       
2019-01-02   38.722500   39.712502  ...   38.562561  148158800
2019-01-03   35.994999   36.430000  ...   34.721451  365248800
2019-01-04   36.132500   37.137501  ...   36.203678  234428400
2019-01-07   37.174999   37.207500  ...   36.123104  219111200
2019-01-08   37.389999   37.955002  ...   36.811718  164101200
...                ...         ...  ...         ...        ...
2020-12-23  132.160004  132.429993  ...  130.960007   88223700
2020-12-24  131.320007  133.460007  ...  131.970001   54930100
2020-12-28  133.990005  137.339996  ...  136.690002  124486200
2020-12-29  138.050003  138.789993  ...  134.869995  121047300
2020-12-30  135.580002  135.990005  ...  133.720001   96452100

这与使用:

yahoo_financials = YahooFinancials(ticker)
historical_price = yahoo_financials.get_historical_price_data('2020-01-05', '2021-01-05', 'weekly')
pd.DataFrame(historical_price['AAPL']['prices'])

相关问题 更多 >