Pandas' corrwith usage about SPY vs. ^GSPC
Pandas' corrwith work fine with SPY but not OK with ^GSPC. Can anybody help me ? Thanks in advance.
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
the error messages:
runfile('D:/@@@pg/yahoo_final_Chang/150830__Revised/test.py', wdir='D:/@@@pg/yahoo_final_Chang/150830__Revised')
Traceback (most recent call last):
File "", line 1, in
File "C:Anacondalibsite-packagesspyderlibwidgetsexternalshellsitecustomize.py", line 682, in runfile execfile(filename, namespace)
File "C:Anacondalibsite-packagesspyderlibwidgetsexternalshellsitecustomize.py", line 71, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc)
File "D:/@@@pg/yahoo_final_Chang/150830__Revised/test.py", line 16 STOCKCORR = np.round(STOCK['PercentA'].corrwith(STOCK['PercentA'].^GSPC),3)
^ SyntaxError: invalid syntax
上一篇: 导入器错误:无法导入名称Split
下一篇: 熊猫的使用关于SPY与^ GSPC的比较