. Advertisement .
..3..
. Advertisement .
..4..
As advised, I used some code samples in another forum, but it could not improve the problem. My question is the “series’ object has no attribute ‘reshape’” in python – how to solve it? The command line is:
Ys = scaler.fit_transform(Y)
Ys = scaler.fit_transform(Y.reshape(-1,1))
and the result:
ValueError: Expected 2D array, got 1D array instead:
AttributeError: 'Series' object has no attribute 'reshape'
What does the message mean? Can you advise me to fix it? If you have other better answers, leave them in the answer box below.
The cause: Because Series only offers an interface for
values
rather than areshape
interface, the error ‘series’ object has no attribute ‘reshape’ results.Solution:
Don’t use:
You should change by this:
It is possible to solve the problem by:
Y.values.reshape(-1,1)
This creates a numpy array containing the values for your pandas Series object, and then transforms it into a 2D array.
This is because pandas Series objects by design are one-dimensional. If you want to remain within the pandas library, another solution is to convert the Series into a DataFrame. This would make the Series 2D.