pyspark : NameError: name 'spark' is not defined

后端 未结 3 828
余生分开走
余生分开走 2020-12-24 08:40

I am copying the pyspark.ml example from the official document website: http://spark.apache.org/docs/latest/api/python/pyspark.ml.html#pyspark.ml.Transformer



        
3条回答
  •  北海茫月
    2020-12-24 09:03

    Since you are calling createDataFrame(), you need to do this:

    df = sqlContext.createDataFrame(data, ["features"])
    

    instead of this:

    df = spark.createDataFrame(data, ["features"])
    

    spark stands there as the sqlContext.


    In general, some people have that as sc, so if that didn't work, you could try:

    df = sc.createDataFrame(data, ["features"])
    

提交回复
热议问题