【问题标题】:TypeError: 'DataFrame' object is not callable using Pandas in PythonTypeError:“DataFrame”对象不能在 Python 中使用 Pandas 调用
【发布时间】:2021-11-01 02:23:42
【问题描述】:

我有一个问题……

我已经编写了这些:

# 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()

我收到此错误:

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

有什么想法吗?我能做什么?

我认为问题在于“加载数据”。如何插入自己的数据集?

提前谢谢你!!

索菲亚

【问题讨论】:

  • 错误出现在第 44 行(或您发布的代码的第 21 行)您从哪里获得 n_samples、n_features、n_informative、n_redundant 或 n_clusters_per_class?它似乎不是 Pandas DataFrame 的一部分。您能否提供 CSV 输入的单行示例?
  • @MattB 我的 CSV 的第一行:10;4290;148663;150

标签: python pandas dataframe cluster-analysis


【解决方案1】:

通过这样做:

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

您正在创建一个从 CSV 文件中读取并存储在名为 dataset 的变量中的 pandas DataFrame。

稍后,您尝试调用 dataset 并向其传递一堆参数:

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

但是由于dataset 是一个pandas DataFrame 对象而不是一个函数,所以你不能调用它,这就是你得到错误的原因。

您可能想要调用一些其他函数,该函数将获取这些参数并返回您尝试分配给X 和y 变量的两个值的元组。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-23
    • 2017-06-17
    • 1970-01-01
    • 2017-10-04
    • 2018-01-08
    • 2014-02-05
    • 2018-02-01
    相关资源
    最近更新 更多