小编use*_*519的帖子

Sklearn 转换错误:预期的二维数组,而是得到一维数组

我使用 sklearn 使用此代码转换数据。

sc = MinMaxScaler()

test= df['outcome']
y = sc.fit_transform(test) 
Run Code Online (Sandbox Code Playgroud)

它显示这样的错误。

ValueError: Expected 2D array, got 1D array instead:
array=[ 21000. 36000.  5000. ...  7000.  12000.  11000.].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
Run Code Online (Sandbox Code Playgroud)

如何解决?

python arrays scikit-learn

4
推荐指数
2
解决办法
4477
查看次数

我可以检查熊猫数据帧索引是否结束?

我使用 while 循环在数据框中显示数据

while True:
    last_id = get_last_id()
    res = df.iloc[last_id + 1]
Run Code Online (Sandbox Code Playgroud)

当 last_id 数据结束并仍然使用 last_id + 1 时显示错误

IndexError: single positional indexer is out-of-bounds
Run Code Online (Sandbox Code Playgroud)

我可以检查数据帧索引中是否没有 last_id + 1 然后不显示任何内容吗?

python dataframe python-3.x pandas

3
推荐指数
1
解决办法
270
查看次数

标签 统计

python ×2

arrays ×1

dataframe ×1

pandas ×1

python-3.x ×1

scikit-learn ×1