【发布时间】:2017-01-03 23:41:00
【问题描述】:
我在尝试绘制 pandas dataframe 时遇到以下错误:
ValueError: num 必须是 1
代码:
import matplotlib.pyplot as plt
names = ['buying', 'maint', 'doors', 'persons', 'lug_boot', 'safety']
custom = pd.DataFrame(x_train) //only a portion of the csv
custom.columns = names
custom.hist()
plt.show()
我尝试从csv 再次读取文件,但我得到了完全相同的错误。
编辑:
print 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]]
编辑2:
完整的错误列表(Traceback):
Traceback(最近一次调用最后一次):
文件“temp.py”,第 104 行,在 custom.dropna().hist()
文件“/home/kostas/anaconda2/lib/python2.7/site-packages/pandas/tools/plotting.py”,第 2893 行,在 hist_frame 布局=布局)
文件“/home/kostas/anaconda2/lib/python2.7/site-packages/pandas/tools/plotting.py”,第 3380 行,在 _subplots ax0 = fig.add_subplot(nrows, ncols, 1, **subplot_kw)
文件“/home/kostas/anaconda2/lib/python2.7/site-packages/matplotlib/figure.py”,第 1005 行,在 add_subplot a = subplot_class_factory(projection_class)(self, *args, **kwargs)
init 中的文件“/home/kostas/anaconda2/lib/python2.7/site-packages/matplotlib/axes/_subplots.py”,第 64 行 maxn=rows*cols, num=num))
【问题讨论】:
-
你能显示
x_train包含的内容吗? -
@gowrath 它是一个
numpy数组,包含标准化的浮点数[0...1](它有 6 列和大约 1600 行) -
@AmiTavory 让我打印
x_train(我会稍等片刻编辑帖子) -
@gowrath 添加了
print x_train输出 -
@KostasRim 你能试试
custom.dropna().hist()吗?