RobustScaler().fit_transform(df['sex'])
error:
Expected 2D array, got 1D array instead:
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
when I tried to reshape my array
RobustScaler().fit_transform(df['sex'].reshape(1,-1))
it's shows me this error:
'Series' object has no attribute 'reshape'
CodePudding user response:
You can try two ways:
RobustScaler().fit_transform(df['sex'].values.reshape(1,-1))
RobustScaler().fit_transform(df[['sex']])
1st converts df series to numpy array and then reshape it to 2-d. 2nd takes a dataframe containing one column instead of series.