2014-06-26 210 views
0

我有一個情況,我有一個名爲Spy%C的列。使用df [「Spy%C」]很容易訪問,但是在嘗試執行df.Spy%C時出現解析錯誤。此外,當我嘗試使用StatsModels.formula.api對列進行迴歸時,我也得到一個解析錯誤以及下面的代碼。選擇帶特殊字符的列

result = sm.ols(formula='Spy%C ~ SpyVol%C', data=df).fit() 
print result.summary() 

處理這個問題的正確格式是什麼?

+0

嘗試'Q' http://patsy.readthedocs.org/en/v0.2.1/builtins-reference.html#patsy.builtins.Q但我不確定它是否適用於'%'。如果它不起作用,那麼你可能需要清理你的名字。 – user333700

+0

看到警告有點[這裏](http://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access) – Jeff

回答

0

df.Spy%C in python means df.Spy.__mod__(C),對於不是標識符的列,您不能使用該地址模式。所以如果你有一個名爲'Syp%C'的列,只需要用df['Syp%C']來解決。