AttributeError: 'Series' object has no attribute 'reshape'

Harvey picture Harvey · Dec 11, 2018 · Viewed 65.9k times · Source

I'm using sci-kit learn linear regression algorithm. While scaling Y target feature with:

Ys = scaler.fit_transform(Y)

I got

ValueError: Expected 2D array, got 1D array instead:

After that I reshaped using:

Ys = scaler.fit_transform(Y.reshape(-1,1))

But got error again:

AttributeError: 'Series' object has no attribute 'reshape'

So I checked pandas.Series documentation page and it says:

reshape(*args, **kwargs) Deprecated since version 0.19.0.

Answer

Harvey picture Harvey · Dec 11, 2018

Solution was linked on reshaped method on documentation page.

Insted of Y.reshape(-1,1) you need to use:

Y.values.reshape(-1,1)