Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 valueError: expected 2d, got 1d instead
Googling this problem it only seems to come up when using a classifier, though I'm trying to normalise a column, and it seems to need a 2d array, but I'm not sure how I would make a 2d array out of my single column:

wgt_l1 = normalize(data.wgt, norm='l1')
wgt_l2= normalize(data.wgt, norm='l2')
Considering my weighting ranges from over 400,000 to below 20,000 means I should probably normalise it, though I can't seem to get the method to run properly. Not as much the actual code, but can I ask why it is necessary to need a 2d array to normalise?

Error msg:
Please find a small sample of numbers (can change to whatever typing necessary, currently in float as the error message mentioned float but I'd rather it be int):
I would try to do something like:
But then I get the error:
AttributeError: 'Series' object has no attribute 'reshape'

data['wgt'] = MinMaxScaler().fit_transform(data['wgt'].values.reshape(-1,1))
Got it with this, though I still don't understand why it must be 2d?
As per the error message, data.wgt is a pandas.Series object. You can get the data in a numpy array, which has the 'reshape' method, by accessing the 'values' attribute.
data.wgt.values.reshape(-1, 1)
A quick look at the Pandas docs point towards using 'to_numpy()' instead
data.wgt.to_numpy().reshape(-1, 1)

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  ValueError: Buffer dtype mismatch, expected 'Python object' but got 'long long' MaJeFi 2 4,199 Mar-20-2019, 06:00 AM
Last Post: MaJeFi

Forum Jump:

Users browsing this thread: 1 Guest(s)