首页 > 解决方案 > IllegalArgumentException: '字段 "class" 不存在。\n可用字段: id, category'

问题描述

我使用的代码是

from pyspark.ml.feature import StringIndexer

indexer = StringIndexer(inputCol = 'class', outputCol = 'classIndex')
indexed = indexer.fit(df).transform(df)

indexed.show()

我收到以下错误

During handling of the above exception, another exception occurred:

IllegalArgumentException                  Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pyspark/sql/utils.py in deco(*a, **kw)
 77                 raise QueryExecutionException(s.split(': ', 1)[1], stackTrace)
 78             if s.startswith('java.lang.IllegalArgumentException: '):
---> 79                 raise IllegalArgumentException(s.split(': ', 1)[1], stackTrace)
 80             raise
 81     return deco

IllegalArgumentException: 'Field "class" does not exist.\nAvailable fields: id, category'

如何解决?

标签: javapythonindexingpyspark

解决方案


推荐阅读