Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: 'DataFrameReader' object is not callable

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?

like image 657
MSS Avatar asked Nov 27 '17 13:11

MSS


People also ask

How to Fix TypeError DataFrame object is not callable?

The way to resolve this error is to simply use square [ ] brackets when accessing the points column instead round () brackets: What is this? We're able to calculate the mean of the points column (18.25) without receiving any error since we used squared brackets.

Why is DataFrame not callable?

Unfortunately, the Python console returns the error message “TypeError: 'DataFrame' object is not callable” after executing the previous Python syntax. The reason for this is that we have tried to use round parentheses to select the variable x3 (i.e. data('x3')).

What does Series object is not callable mean?

The Python "TypeError: 'Series' object is not callable" occurs when we try to call a Series object as if it were a function. To solve the error, resolve any clashes between function and variable names and don't override built-in functions.


1 Answers

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

Silly Me!

like image 51
MSS Avatar answered Oct 06 '22 01:10

MSS