【发布时间】:2021-05-10 14:18:58
【问题描述】:
{simpleDF.columns
#output :['color', 'lab', 'value1', 'value2']
indexer = simpleDF.select('lab')
from pyspark.ml.feature import StringIndexer
# Let us create an object of the class StringIndexer
lblindexer=StringIndexer().setInputCol(indexer).setOutputCol("LabelIndexed")
idxRes=lblindexer.fit(simpleDF).transform(simpleDF)
idxRes.show(5)}
这行代码运行良好,但我希望它更通用
#lblindexer=StringIndexer().setInputCol('lab').setOutputCol("LabelIndexed")
得到错误:
TypeError:为参数“inputCol”提供的参数值无效。无法将
【问题讨论】:
-
您的注释代码不起作用正在将字符串传递给 setInputCol。 setInputCol 是否接受字符串?当您将它传递给 simpleDf.select(). 时,看起来您已经开始工作了
标签: apache-spark pyspark apache-spark-ml