我正在将psv文件加载到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
答案 0 :(得分:5)
您正尝试使用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")