我计划在包含数值数据的CSV集上运行scikit-learn Stochastic Graduent Booster算法。
当调用脚本的X = Germany.drop('Status', axis='columns')
时,我收到的是AttributeError: 'numpy.ndarray' object has no attribute 'drop'
。
我假设这个错误可能与我正在转换CSV数据pd.to_numeric
的事实有关,这可能也转换了字符串头。有没有任何智能调整可以使此运行?
CSV数据具有以下结构:
x1c 0d1x的数据
相应的代码如下所示:
Germany = pd.read_csv('./Germany_filtered.csv', index_col=0)
Germany = Germany.fillna("")
Germany = pd.to_numeric(Germany.columns.str, errors='coerce')
Germany.head()
X = Germany.drop('Status', axis='columns')
y = Germany['Status']
字符串
1条答案
按热度按时间ryevplcw1#
字符串
drop
在一个嵌套框架上工作正常:型
to_numeric
生成一个numpy数组:型
在进入
drop
之前,它应该抱怨head
:型
to_numeric
docs是怎么说的?我没有使用过,但显然你不想传递df.columns.str
对象。我没有使用过这个函数,但让我们尝试传递它的结构:型
所以让我们传递一个列/系列:
得到的
Series
可以在同一列或新的列中被分配回该矩阵:型
现在在我的例子框架中,没有必要做这种转换,但它应该给你给予一些东西。
让我们尝试一个真实的字符串转换:
链接的答案没有帮助:
但我的版本确实产生了一个数字序列: