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: The truth value of a Series is ambiguous ? firebird 1 188 Aug-01-2019, 12:33 AM
Last Post: scidam
  TypeError: expected string or bytes-like object twinpiques 1 1,729 May-06-2019, 08:29 PM
Last Post: Yoriz
  ValueError: Input contains infinity or a value too large for dtype('float64') Rabah_r 1 1,135 Apr-06-2019, 11:08 AM
Last Post: scidam
  ValueError: Buffer dtype mismatch, expected 'Python object' but got 'long long' MaJeFi 2 1,624 Mar-20-2019, 06:00 AM
Last Post: MaJeFi
  Why I get the ValueError vokoyo 0 453 Mar-16-2019, 06:38 PM
Last Post: vokoyo
  ValueError: shapes naveen73 0 288 Jan-27-2019, 01:15 PM
Last Post: naveen73
  ValueError: Found input variables with inconsistent numbers of samples: [0, 3] ayaz786amd 2 3,064 Nov-27-2018, 07:12 AM
Last Post: ayaz786amd
  ValueError: could not convert the string to float Grin 3 5,161 Jun-14-2018, 08:17 PM
Last Post: killerrex
  ValueError: The truth value of an array with more than one element is ambiguous. Eliza5 1 8,255 Apr-02-2018, 12:03 AM
Last Post: scidam
  Error: ValueError: could not convert string to float: 'L200 1.6 D/C' Jaarroy 2 2,895 Jan-18-2018, 02:00 PM
Last Post: Jaarroy

Forum Jump:

Users browsing this thread: 1 Guest(s)