9
votes

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?

2
What are you expecting datasets.values to be? - user2357112 supports Monica
i am expecting this is as a row? - T.Setso
A pandas Dataframe or Dataset (column of a frame) has a .values attribute (probably a property). The result in is numpy array. But don't try to apply that twice. An array does not have a values attribute. Check the type of datasets or whatever object your error is complaining about. - hpaulj
Hmm, cant follow you. so i cant use a array to shift like the way i want to? datasets is a array yes - T.Setso
If it is already an array, you don't to add values. - hpaulj

2 Answers

11
votes

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

0
votes

The problem lies in the following line:

df = StandardScaler().fit_transform(df) It returns a numpy array (see docs), which does not have a drop function. You would have to convert it into a pd.DataFrame first!

new_df = pd.DataFrame(StandardScaler().fit_transform(df), columns=df.columns, index=df.index)