想要开始使用Panda的get_data_yahoo方法将Yahoo数据加载到面板数据集中。
所以我有以下设置
all_data={}
for ticker in ['GOOG','AAPL','XOM']:
all_data[ticker]=web.get_data_yahoo(ticker,'04/11/2014','04/14/2014')
,输出低于
{'GOOG': Open High Low Close Volume Adj Close
Date
2014-04-11 532.55 540.0 526.53 530.60 3914100 530.60
2014-04-14 538.25 544.1 529.56 532.52 2568000 532.52
[2 rows x 6 columns], 'AAPL': Open High Low Close Volume Adj Close
Date
2014-04-11 519.0 522.83 517.14 519.61 9704200 519.61
2014-04-14 521.9 522.16 517.21 521.68 7345500 521.68
[2 rows x 6 columns], 'XOM': Open High Low Close Volume Adj Close
Date
2014-04-11 96.51 97.44 96.28 96.72 13352500 96.72
2014-04-14 97.49 98.06 96.74 97.86 9610200 97.86
我想在每个抓取器上为每个抓取器添加一个单独的列,如
Date Ticker Open High Low Close Volume Adj Close
2014-04-11 GOOG xxx xxx xxx xxx xxx xxx
2014-04-14 GOOG xxx xxx xxx xxx xxx xxx
2014-04-11 AAPL xxx xxx xxx xxx xxx xxx
2014-04-14 AAPL xxx xxx xxx xxx xxx xxx
2014-04-11 XOM xxx xxx xxx xxx xxx xxx
2014-04-14 XOM xxx xxx xxx xxx xxx xxx
我怎样才能做到这一点?
谢谢!
答案 0 :(得分:3)
您可以执行以下操作:
data=[]
for ticker in ['GOOG','AAPL','XOM']:
x = web.get_data_yahoo(ticker,'04/11/2014','04/14/2014')
x['ticker'] = ticker
data.append(x)
print pd.concat(data)
Open High Low Close Volume Adj Close ticker
Date
2014-04-11 532.55 540.00 526.53 530.60 3914100 530.60 GOOG
2014-04-14 538.25 544.10 529.56 532.52 2568000 532.52 GOOG
2014-04-11 519.00 522.83 517.14 519.61 9704200 519.61 AAPL
2014-04-14 521.90 522.16 517.21 521.68 7345500 521.68 AAPL
2014-04-11 96.51 97.44 96.28 96.72 13352500 96.72 XOM
2014-04-14 97.49 98.06 96.74 97.86 9610200 97.86 XOM