熊猫的使用关于SPY与^ GSPC的比较

Pandas'corrwith与SPY很好地工作,但与^ GSPC不一致。 有谁能够帮助我 ? 提前致谢。

import pandas.io.data as web                   
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import csv

Symbol = ['^GSPC','SPY','XLK','XLV','XLY','XLP','XLE','XLF','XLI','XLB','XLU']

STOCK = web.DataReader(name=Symbol,data_source='yahoo',start='2000-1-1',end='2009-3-1')

STOCK['PercentA'] = np.round(np.log(STOCK['Adj Close']/STOCK['Adj Close'].shift(1)),3)

### OK wiht SPY, but not OK wiht ^GSPC
STOCKCORR = np.round(STOCK['PercentA'].corrwith(STOCK['PercentA'].^GSPC),3)     

StockNan = STOCKCORR[~STOCKCORR.isnull()]
StockOrder = StockNan.order().iloc[::-1]
StockRows = StockOrder.iloc[:20]          
print StockRows

错误消息:

runfile('D:/ @@@ pg / yahoo_final_Chang / 150830__Revised / test.py',wdir ='D:/ @@@ pg / yahoo_final_Chang / 150830__Revised')

回溯(最近一次通话最后):

文件“”,第1行,in

运行文件execfile(filename,namespace)中的文件“C: Anaconda lib site-packages spyderlib widgets externalshell sitecustomize.py”,第682行,

文件“C: Anaconda lib site-packages spyderlib widgets externalshell sitecustomize.py”,第71行,在execfile exec(compile(scripttext,filename,'e​​xec'),glob,loc)

文件“D:/ @@@ pg / yahoo_final_Chang / 150830__Revised / test.py”,第16行STOCKCORR = np.round(STOCK ['PercentA'] .corrwith(STOCK ['PercentA']。^ GSPC),3)
^ SyntaxError:无效的语法

链接地址: http://www.djcxy.com/p/55285.html

上一篇: Pandas' corrwith usage about SPY vs. ^GSPC

下一篇: Where is Python's sys.path initialized from?