Pandas dataframe: ValueError: num should be 1 <= num <= 0, not 1

I get the following error while I try to build pandas dataframe:

Error: num value must be 1 <= num <= 0, not 1

the code:

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

I tried to read the file from again csv, and I get the same error.

Edit:

print x_train conclusion:

[[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.333333333333333333 0.3333333333333333 2.0 2.0 2.0 2.0]

[0.0 0.0 3.0 3.0 3.0 3.0]]

Edit2:

Full list of errors (Traceback):

Traceback (last last call):

File "temp.py", line 104, in custom.dropna (). Hist ()

File "/home/kostas/anaconda2/lib/python2.7/site-packages/ pandas / tools / plotting.py", line 2893, in hist_frame layout scheme =)

"/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)

"/home/kostas/anaconda2/lib/python2.7/site-packages/matplotlib/axes/_subplots.py", 64, init    maxn = rows * cols, num = num))

+4
2

, , train_x. 10 000 6 , , . - len(x_train) len(x_train[0]) 0. , :

ValueError - matplotlib.axes._subplot, ( ). :

""" 
*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))

(. ):

    if num < 1 or num > rows*cols:
     # maxN is the number of rows*cols and since this is showing 0 for you (in your error stacktrace), 
     # it means the number of cols being passed into your histogram is 0. Don't know why though :P
        raise ValueError(      
            "num must be 1 <= num <= {maxn}, not {num}".format(
                maxn=rows*cols, num=num))

, , , . x_train , :

    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])
+1

, , , NumPy , float.

:

x_train = x_train.astype(np.float)
+6

Source: https://habr.com/ru/post/1652687/


All Articles