4

I am loading a csv file into pyspark as follows (within pyspark shell):

>>> from pyspark.sql import SQLContext
>>> sqlContext = SQLContext(sc)
>>> df = sqlContext.read.format('com.databricks.spark.csv').options(header='true').load('data.csv')

but I am getting this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'SQLContext' object has no attribute 'read'
>>> 

I am using spark 1.3.1 and I am trying to use spark-csv

1 Answer 1

7

You are trying to use Spark 1.4+ syntax.

For Spark 1.3

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")
Sign up to request clarification or add additional context in comments.

2 Comments

Actually I am using the python api example of the spark-csv module, github.com/databricks/spark-csv#python-api. which makes use of read as I am doing
@MedAli you are trying to use Spark 1.4+: syntax

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.