Python dataframe:ValueError:num必须为1<;=num<;=0,而不是1

Python dataframe:ValueError:num必须为1<;=num<;=0,而不是1,python,pandas,histogram,Python,Pandas,Histogram,当我试图绘制数据帧时,出现以下错误: ValueError:num必须是1,所以我很确定您的问题与数组train_x的格式有关。我用10000行和6列的数组尝试了你的程序,效果很好,所以问题不在于大小。由于某种原因,len(x\u列)或len(x\u列[0])中的一个为0。是什么让我这么想的: 您得到的ValueError来自matplotlib.axes.\u子图模块,该模块处理在一个大图中绘制许多小子图(因此每个小直方图)。模块的代码如下所示: """ *rows*, *cols*, *n

当我试图绘制数据帧时,出现以下错误:


ValueError:num必须是1,所以我很确定您的问题与数组train_x的格式有关。我用10000行和6列的数组尝试了你的程序,效果很好,所以问题不在于大小。由于某种原因,
len(x\u列)
len(x\u列[0])
中的一个为0。是什么让我这么想的:

您得到的ValueError来自matplotlib.axes.\u子图模块,该模块处理在一个大图中绘制许多小子图(因此每个小直方图)。模块的代码如下所示:

""" 
*rows*, *cols*, *num* are arguments where
the array of subplots in the figure has dimensions *rows*,
*cols*, and where *num* is the number of the subplot
being created. *num* starts at 1 in the upper left
corner and increases to the right.
"""
rows, cols, num = args
rows = int(rows)
cols = int(cols)
if isinstance(num, tuple) and len(num) == 2:
    num = [int(n) for n in num]
    self._subplotspec = GridSpec(rows, cols)[num[0] - 1:num[1]]
else:
    if num < 1 or num > rows*cols:
        raise ValueError(      
            "num must be 1 <= num <= {maxn}, not {num}".format(
                maxn=rows*cols, num=num))
在调用问题中的代码之前,请尝试执行此操作,并查看此操作是否有效:

x_train = list([list(x) for x in x_train])

我也有同样的问题,我发现这是因为NumPy数组是一个对象数组而不是浮点数组

试试这个:

x_train = x_train.astype(np.float)

你能告诉我x_火车包含什么吗?@gowrath这是一个
numpy
数组,包含标准化的浮动[0…1](它有6列,大约1600行)@AmiTavory让我来打印x_火车
x_火车
(我会马上编辑帖子)@gowrath添加了
打印x_火车
output@KostasRim你能试试自定义.dropna().hist()吗
?哇,非常感谢,添加逗号确实解决了这个问题。这只是一个练习。如果我记得的话,我已经找到了一个解决办法。谢谢你的回答!
    x_train =   [[0.0, 0.0, 0.0, 0.0, 0.0, 0.0],

                [1.0, 1.0, 0.0, 0.0, 0.0, 0.0],

                [0.0, 0.0, 0.0, 0.0, 0.0, 0.0],

                [0.0, 0.0, 0.0, 0.0, 0.0, 0.0],

                [0.3333333333333333, 0.3333333333333333, 2.0, 2.0, 2.0, 2.0],

                [0.0, 0.0, 3.0, 3.0, 3.0, 3.0]]
x_train = list([list(x) for x in x_train])
x_train = x_train.astype(np.float)