python - 如何修复 AttributeError : 'Series' object has no attribute 'to_numpy'

标签 python pandas attributeerror

我的输出:

img

def load_data(self):
    """
    Load data from list of paths
    :return: 3D-array X and 2D-array y
    """
    X = None
    y = None
    df = pd.read_excel('data/Data.xlsx', header=None)
    for i in range(len(df.columns)):
        sentences_ = df[i].to_numpy().tolist()
        label_vec = [0.0 for _ in range(0, self.n_class)]
        label_vec[i] = 1.0
        labels_ = [label_vec for _ in range(0, len(sentences_))]
        if X is None:
            X = sentences_
            y = labels_
        else:
            X += sentences_
            y += labels_
    X, max_length = self.tokenize_sentences(X)
    X = self.word_embed_sentences(X, max_length=self.max_length)
    return np.array(X), np.array(y)

这是我使用 Pandas 库作为 pd 的代码。当我在 Google Colab 中运行时,出现以下错误:

AttributeError: 'Series' object has no attribute 'to_numpy'

最佳答案

检查您的 Pandas 库的版本:

import pandas
print(pandas.__version__)

如果您的版本低于 0.24.1:
pip install --upgrade pandas

关于python - 如何修复 AttributeError : 'Series' object has no attribute 'to_numpy' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54650748/

相关文章:

python - 如何在没有 lambda 的情况下对带有 pandas 的列中的外观求和

javascript - 抓取需要您向下滚动的网站

python - Python 中 pandas cut、groupby 和 multiindex 的奇怪行为

python - 从 Dask DataFrame 中删除列数不相等的行

c# - IronPython - "AttributeError: object has no attribute"自定义类

python - pyodbc Access 数据库 MSysObjects 权限问题

python - 如何将全局变量传递给另一个函数调用的函数

python - 具有任意步长的点周围的平均值

python - AttributeError: 'module' 对象没有属性 'hist'

python - AttributeError: 'function' 对象没有属性 'replace'