2017-01-31 59 views
1

沒有屬性這是我的代碼:熊貓 - 浮動對象有九

X_train, X_test, y_train, y_test = train_test_split(sing.ix[:-10], y.ix[:-10].T.corr(), test_size=0.2) 

,但我得到這個錯誤:

--------------------------------------------------------------------------- 
AttributeError       Traceback (most recent call last) 
<ipython-input-78-32ea47dd4970> in <module>() 
     1 # Split data into train and test leaving last ten (10) rows for the final evaluation 
----> 2 X_train, X_test, y_train, y_test = train_test_split(sing.ix[:-10], y.ix[:-10].T.corr(), test_size=0.2) 

AttributeError: 'float' object has no attribute 'ix' 

有人能解釋如何解決呢?非常感謝!

+2

它看起來像你期望一個熊貓數據幀,但有一個浮動,而不是 –

+0

'sing'和/或者「y」是一個浮點數。重新審視這些變量的創建,以確保它們符合您的期望。 – 3novak

+0

謝謝,但是我應該如何將浮動對象轉換爲? – Zucchini

回答

1

試試輸入:

print(type(sing)) # This will output object type of variable. 
print(type(y)) 

,並確認它們都是數據幀的對象。

還找方法屬於對象類型嘗試鍵入:

# This will print a list of defined methods according to object type. 
print(dir(sing)) 

# Displays documentation according to object/class 
help(object type) # Ex. pandas.core.frame.DataFrame 
+0

這就是我得到的:所以y是浮動對象... – Zucchini

+0

我不熟悉sklearn庫,試圖完成,我沒用。以下是一些與方法train_test_split()相關的文檔http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html。雖然,您無法將對象類型爲float的屬性ix使用。 –