T.Setso
T.Setso

Reputation: 625

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

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?

Upvotes: 15

Views: 105579

Answers (2)

Michael
Michael

Reputation: 21

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)

Upvotes: 2

T.Setso
T.Setso

Reputation: 625

The solution:

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

Upvotes: 26

Related Questions