1
x = df.x_value
y = df.y_value    
x = x[:, np.newaxis]
y = y[:, np.newaxis]    
polynomial_features= PolynomialFeatures(degree=2)
x_transformed = polynomial_features.fit_transform(x) 

The above code is giving following warning...how can I avoid these

FutureWarning: Support for multi-dimensional indexing (e.g. `obj[:, None]`) is deprecated and will be removed in a future version.  Convert to a numpy array before indexing instead.
hpaulj
  • 221,503
  • 14
  • 230
  • 353
begining
  • 73
  • 3
  • 9
  • Does this answer your question? [FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated use \`arr\[tuple(seq)\]\` instead of \`arr\[seq\]\`](https://stackoverflow.com/questions/52110869/futurewarning-using-a-non-tuple-sequence-for-multidimensional-indexing-is-depre) – alex Aug 13 '21 at 07:50
  • @alex, that's a different warning – hpaulj Aug 13 '21 at 10:26

1 Answers1

2

A full working example with solution as suggested by the warning:

In [194]: df
Out[194]: 
   age  rank  height  weight
0   20     2     155      53
1   15     7     159      60
2   34     6     180      75
3   40     5     163      80
4   60     1     170      49
In [195]: df.height
Out[195]: 
0    155
1    159
2    180
3    163
4    170
Name: height, dtype: int64
In [196]: df.height[:,None]
<ipython-input-196-1af0bb09495a>:1: FutureWarning: Support for multi-dimensional indexing (e.g. `obj[:, None]`) is deprecated and will be removed in a future version.  Convert to a numpy array before indexing instead.
  df.height[:,None]
Out[196]: 
array([[155],
       [159],
       [180],
       [163],
       [170]])
In [197]: df.height.to_numpy()[:,None]
Out[197]: 
array([[155],
       [159],
       [180],
       [163],
       [170]])
hpaulj
  • 221,503
  • 14
  • 230
  • 353
  • Do you know if the to_numpy() method is the only way to get around this? I'm getting the same FutureWarning when I try to use matplotlib to *plot* the output of a `df.xs()` call. I plot DataFrames and Series all the time and am constantly hitting this; it seems a bit onerous to have to be putting `.to_numpy()` everywhere... – Ajean Jan 05 '22 at 19:01