考拉与 Sklearn 不兼容 - ValueError: 无法将字符串转换为浮点数: 'x'



我试图适应Koalas——Pandas:运行良好的代码

import pandas as pd
from databricks import koalas as ks
from sklearn import preprocessing
pdf = pd.DataFrame({'x':range(3), 'y':[1,2,5], 'z':[100,200,1000]})
df = ks.from_pandas(pdf)
min_max_scaler = preprocessing.MinMaxScaler()
result = min_max_scaler.fit_transform(df)

它在最后一行失败,并出现以下错误:

ValueError: could not convert string to float: 'x'

Koalas中的标题行似乎被fit_transform函数解释为正常行。

有什么变通办法吗?

谢谢。

您将通过更改获得更多信息

df = ks.from_pandas(pdf)

df = ks.from_pandas(pdf).set_index('x')

以明确地使CCD_ 2成为熊猫和考拉数据帧中的索引列。

最新更新