15

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

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

This is 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 file (number sequence) just has integers ordered like:

1
2
3
4
5
n

How should I handle it?

6
  • What are you expecting datasets.values to be? Commented Jan 10, 2017 at 2:07
  • i am expecting this is as a row? Commented Jan 10, 2017 at 2:09
  • 1
    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. Commented Jan 10, 2017 at 2:24
  • Hmm, cant follow you. so i cant use a array to shift like the way i want to? datasets is a array yes Commented Jan 10, 2017 at 2:27
  • 2
    If it is already an array, you don't to add values. Commented Jan 10, 2017 at 3:05

2 Answers 2

27

The solution:

The given dataset was already an array, so I didn’t need to call .value.

Sign up to request clarification or add additional context in comments.

Comments

3

The problem lies in the following line:

df = StandardScaler().fit_transform(df)

It returns a NumPy array (see the documentation), 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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.