Pandas - float对象没有属性ix

时间:2017-01-31 03:18:48

标签: python pandas

这是我的代码:

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'

有人可以解释如何修复它吗?非常感谢!

1 个答案:

答案 0 :(得分:1)

尝试输入:

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