python - Pandas - float 对象没有属性 ix

标签 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'

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

最佳答案

尝试输入:

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/

相关文章:

python - 带有结合了两个函数的 aggfunc 的数据透视表

python - 查找数据框中的所有依赖项

python - 将 Base 64 字符串解码为文件

python - 为什么我得到 'list' object has no attribute 'items' ?

python - 无法获得包含序列号的完整 VISA 地址

python - 按时间间隔分组并查找具有相似最小值(进入时间值)的唯一 ID

python - 根据列表项的索引模进行不同的操作

python - 在条件语句后设置数据框

python - AWS 胶水 : Failed to start job run due to missing metadata

python - 为什么 Pandas Web Scraping 不能从该网站打印出任何表格?