Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'numpy.ndarray' object has no attribute 'values'

I want to shift my time series data, but getting following error:

AttributeError: 'numpy.ndarray' object has no attribute 'values'

Thats my Code:

def create_dataset(datasets):
    #series = dataset
    temps = DataFrame(datasets.values)
    dataframes = concat(
        [temps, temps.shift(-1), temps.shift(-2), temps.shift(-3)], axis=1)
    lala = numpy.array(dataframes)
    return lala

    #load
    dataframe = pandas.read_csv('zahlenreihe.csv', index_col=False,   
    engine='python', header=None)
    dataset = dataframe.values
    dataset = dataset.astype('float32')

    #split 
    train_size = int(len(dataset) * 0.70)
    test_size = len(dataset) - train_size
    train, test = dataset[0:train_size,:], dataset[train_size:len(dataset),:]

    #create
    trainX = create_dataset(train)

I think the following line is wrong:

temps = DataFrame(datasets.values)

My zahlenreihe.csv just has integers ordered like:

  1
  2
  3
  4
  5
  n

How should i handle it?

like image 652
T.Setso Avatar asked Jan 10 '17 02:01

T.Setso


People also ask

How to fix NumPy ndarray object has no attribute append?

This error occurs when you attempt to append one or more values to the end of a NumPy array by using the append() function in regular Python. Since NumPy doesn't have an append attribute, an error is thrown. To fix this, you must use np. append() instead.

How do I change Ndarray to list?

To convert a NumPy array (ndarray) to a Python list use ndarray. tolist() function, this doesn't take any parameters and returns a python list for an array. While converting to a list, it converts the items to the nearest compatible built-in Python type.

How do you find the length of a Ndarray?

shape to get Length. So for multi-dimensional NumPy arrays use ndarray. shape function which returns a tuple in (x, y), where x is the number of rows and y is the number of columns in the array. You can now find the total number of elements by multiplying the values in the tuple with each other.

What is NP where in Python?

where() function returns the indices of elements in an input array where the given condition is satisfied. Syntax :numpy.where(condition[, x, y]) Parameters: condition : When True, yield x, otherwise yield y. x, y : Values from which to choose.


1 Answers

The solution: the given dataset was already an array, so I didnt need to call .value.

like image 200
T.Setso Avatar answered Sep 23 '22 13:09

T.Setso