我将csv文件加载到pyspark中,如下所示(在pyspark shell中):
>>> from pyspark.sql import SQLContext
>>> sqlContext = SQLContext(sc)
>>> df = sqlContext.read.format('com.databricks.spark.csv').options(header='true').load('data.csv')
但我收到这个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'SQLContext' object has no attribute 'read'
>>>
我正在使用spark 1.3.1,我正在尝试使用spark-csv
解决方法:
您正在尝试使用Spark 1.4语法.
from pyspark.sql import SQLContext
sqlContext = SQLContext(sc)
df = sqlContext.load(source="com.databricks.spark.csv", header="true", path = "cars.csv")
df.select("year", "model").save("newcars.csv", "com.databricks.spark.csv")