这是我的代码:
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'
有人可以解释一下如何修复它吗?非常感谢!
最佳答案
尝试输入:
print(type(sing)) # This will output object type of variable.
print(type(y))
并验证它们都是 DataFrame 对象。
还要查找与对象类型相关的方法,请尝试键入:
# 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
关于python - Pandas - float 对象没有属性 ix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41949106/