close

[Solved] AttributeError: ‘Series’ object has no attribute ‘reshape’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error AttributeError: ‘Series’ object has no attribute ‘reshape’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How AttributeError: ‘Series’ object has no attribute ‘reshape’ Error Occurs?

Today I get the following error AttributeError: ‘Series’ object has no attribute ‘reshape’ in python.

How To Solve AttributeError: ‘Series’ object has no attribute ‘reshape’ Error ?

  1. How To Solve AttributeError: 'Series' object has no attribute 'reshape' Error ?

    To Solve AttributeError: 'Series' object has no attribute 'reshape' Error This extracts a numpy array with the values of your pandas Series object and then reshapes it to a 2D array.

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

    To Solve AttributeError: 'Series' object has no attribute 'reshape' Error This extracts a numpy array with the values of your pandas Series object and then reshapes it to a 2D array.

Solution 1

Solution was linked on reshaped method on documentation page.

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

Y.values.reshape(-1,1)

Solution 2

The solution is indeed to do:

Y.values.reshape(-1,1)

This extracts a numpy array with the values of your pandas Series object and then reshapes it to a 2D array.

The reason you need to do this is that pandas Series objects are by design one dimensional. Another solution if you would like to stay within the pandas library would be to convert the Series to a DataFrame which would then be 2D:

Y = pd.Series([1,2,3,1,2,3,4,32,2,3,42,3])

scaler = StandardScaler()

Ys = scaler.fit_transform(pd.DataFrame(Y))

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read