5

I am using PySpark to read a csv file. Below is my simple code.

from pyspark.sql.session import SparkSession

def predict_metrics():
    session = SparkSession.builder.master('local').appName("PredictFacebookMetrics").getOrCreate()
    dataframe = session.read().format('com.databricks.spark.csv') \
        .option('header', True) \
        .option('delimiter', ';') \
        .option('inferSchema', True) \
        .load(r'D:\M\Facebook_metrics_data\dataset_Facebook.csv')
    dataframe.printSchema()
    dataframe.show(False)

if __name__=='__main__':
    predict_metrics()

Upon executing above code I get the following error:

TypeError: 'DataFrameReader' object is not callable

What is the solution to this error?

2
  • 2
    It is session.read.format.... instead of session.read().format.. :) Commented Nov 27, 2017 at 13:57
  • 1
    Yes, that did it. Thank you! Commented Nov 27, 2017 at 14:04

1 Answer 1

8

As suggested in comment, It should be session.read.format instead of session.read().format

Silly Me!

Sign up to request clarification or add additional context in comments.

Comments

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.