AnalysisException: u"cannot resolve 'name' given input columns: [ list] in sqlContext in spark

前端 未结 3 920
庸人自扰
庸人自扰 2021-02-19 08:30

I tried a simple example like:

data = sqlContext.read.format(\"csv\").option(\"header\", \"true\").option(\"inferSchema\", \"true\").load(\"/databricks-datasets/         


        
3条回答
  •  花落未央
    2021-02-19 09:13

    I found the issue: some of the column names contain white spaces before the name itself. So

    data = data.select(" timedelta", " shares").map(lambda r: LabeledPoint(r[1], [r[0]])).toDF()
    

    worked. I could catch the white spaces using

    assert " " not in ''.join(df.columns)  
    

    Now I am thinking of a way to remove the white spaces. Any idea is much appreciated!

提交回复
热议问题