2

我想从雅虎下载调整后的收盘价及其相应的日期,但我似乎无法弄清楚如何从pandas DataFrame.

我正在阅读这个问题的答案

from pandas.io.data import DataReader
from datetime import datetime
goog = DataReader("GOOG",  "yahoo", datetime(2000,1,1), datetime(2012,1,1))
print goog["Adj Close"]

这部分工作正常;但是,我需要提取与价格对应的日期。

例如:

adj_close = np.array(goog["Adj Close"])

给我一个调整后收盘价的一维数组,我正在寻找一维日期数组,例如:

date = # what do I do?

adj_close[0]对应于date[0]

当我做:

>>> goog.keys()
Index([Open, High, Low, Close, Volume, Adj Close], dtype=object)

我看到没有一个键会给我任何类似于日期的东西,但我认为必须有一种方法来创建日期数组。我错过了什么?

4

2 回答 2

4

您可以通过goog.index它存储为 DateTimeIndex 来获取它。要获得一系列日期,您可以执行

goog.reset_index()['Date']
于 2013-08-13T09:07:17.933 回答
1
import numpy as np
import pandas as pd
from pandas.io.data import DataReader

symbols_list = ['GOOG','IBM']
d = {}
for ticker in symbols_list:
    d[ticker] = DataReader(ticker, "yahoo", '2014-01-01')
pan = pd.Panel(d)
df_adj_close = pan.minor_xs('Adj Close') #also use 'Open','High','Low','Adj Close' and 'Volume'

#the dates of the adjusted closes from the dataframe containing adjusted closes on multiple stocks
df_adj_close.index

# create a dataframe that has data on only one stock symbol
df_individual = pan.get('GOOG')

# the dates from the dataframe of just 'GOOG' data
df_individual.index
于 2014-12-16T08:30:57.217 回答