Sofia Vlachou
Sofia Vlachou

Reputation: 55

TypeError: 'DataFrame' object is not callable using Pandas in Python

I have a question…

I’ve programmed these:

# Dependencies
import pandas as pd
from numpy import where
from matplotlib import pyplot

# Load Data
names = [“Frequency”,”Comments Count”,”Likes Count”,”Text nwords”]

dataset = pd.read_csv(“Posts.csv”, encoding=”utf-8″, sep=”;”, delimiter=None,
names=names, delim_whitespace=False,
header=0, engine=”python”)

X = dataset.values[:,0:2]
y = dataset.values[:,3]
# Explore Data
print(dataset.shape)
print(dataset.head(10))
print(dataset.describe())
print(dataset.dtypes)

X,y = dataset(n_samples=100, n_features=4, n_informative=4, n_redundant=0, n_clusters_per_class=1, random_state=4)

# create scatter plot for samples from each class
for class_value in range(3):
# get row indexes for samples with this class
row_ix = where(y == class_value)
# create scatter of these samples
pyplot.scatter(X[row_ix, 0], X[row_ix, 3])
# show the plot
pyplot.show()

I’m getting this error :

Traceback (most recent call last):

File “C:/Users/USER/pythonProject/main.py”, line 44, in

X,y = dataset(n_samples=100, n_features=4, n_informative=4, n_redundant=0, n_clusters_per_class=1, random_state=4)

TypeError: ‘DataFrame’ object is not callable

Any ideas? What can I do?

I think the problem is about the "load data". How can I insert my own dataset?

Thank you in advance!!

Sofia

Upvotes: 2

Views: 4400

Answers (1)

ThePyGuy
ThePyGuy

Reputation: 18416

By doing this:

dataset = pd.read_csv(“Posts.csv”, encoding=”utf-8″, sep=”;”, delimiter=None,
names=names, delim_whitespace=False,
header=0, engine=”python”)

You are creating a pandas DataFrame that is read from the CSV file and stored in the variable named dataset.

Later, you are trying to call dataset and pass a bunch of arguments to it:

X,y = dataset(n_samples=100, n_features=4, n_informative=4, n_redundant=0, n_clusters_per_class=1, random_state=4)

But since dataset is a pandas DataFrame object and not a function, you can not call it that is why you are getting error.

You probably want to call some other function that will take those parameters and return back a tuple of two values that you are trying to assign to X and y variables.

Upvotes: 1

Related Questions