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?
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.
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')).
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.
As suggested in comment,
It should be session.read.format
instead of session.read().format
Silly Me!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With