DeprecationWarning:在pandas数据框中预处理数据

时间:2016-11-10 00:47:47

标签: python pandas numpy scikit-learn

df:

      cont1     cont2     cont3     cont4     cont5     cont6     cont7  
  0  0.726300  0.245921  0.187583  0.789639  0.310061  0.718367  0.335060   
  1  0.330514  0.737068  0.592681  0.614134  0.885834  0.438917  0.436585   
  2  0.261841  0.358319  0.484196  0.236924  0.397069  0.289648  0.315545   
  3  0.321594  0.555782  0.527991  0.373816  0.422268  0.440945  0.391128   
  4  0.273204  0.159990  0.527991  0.473202  0.704268  0.178193  0.247408 

Code:

from sklearn import preprocessing
min_max_scaler = preprocessing.MinMaxScaler()

for each_column in df.columns:
    df[each_column].reshape(1, -1) #suggested solution
    df[each_column] = min_max_scaler.fit_transform(df[each_column])


Warning:

validation.py:395: DeprecationWarning: Passing 1d arrays as 
data is   deprecated in 0.17 and will raise ValueError in 0.19. 
Reshape your data   either using X.reshape(-1, 1) if your data 
has a single feature or X.reshape(1, -1) if it contains a single sample.
DeprecationWarning)

请告诉我错误是什么,是因为我没有将数据作为numpy数组传递给预处理器吗?

我尝试过建议的解决方案仍然会收到同样的警告。

2 个答案:

答案 0 :(得分:0)

弃用警告告诉您该怎么做。

使用df[each_column].reshape(-1, 1)df[each_column].reshape(1, -1)

如果您阅读Series的文档,您还会看到Pandas在内部使用ndarray

答案 1 :(得分:0)

当某些内容被弃用时,意味着在将来的版本中不再计划支持它。正如消息所解释的那样,传递一维数组将开始在版本0.19中给出错误。如果您正在编写新代码,则应尽量避免使用已弃用的函数,并遵循消息的建议(对数组使用reshape方法)。

是否致电[Fri Nov 11 02:21:08.389721 2016] [rewrite:trace3] [pid 25637:tid 139651102975744] mod_rewrite.c(477): [client 45.67.87.76:57196] 45.67.87.76 - - [site.example.com/sid#7f031c7731e0][rid#7f02f002b310/initial] [perdir /home/someuser/public_html/] add path info postfix: /home/someuser/public_html/folder1/catalog/ABC -> /home/someuser/public_html/folder1/catalog/ABC/10162015/Asdf.jpg, referer: http://site.example.com/widgets/bathroom/ [Fri Nov 11 02:21:08.389764 2016] [rewrite:trace3] [pid 25637:tid 139651102975744] mod_rewrite.c(477): [client 45.67.87.76:57196] 45.67.87.76 - - [site.example.com/sid#7f031c7731e0][rid#7f02f002b310/initial] [perdir /home/someuser/public_html/] strip per-dir prefix: /home/someuser/public_html/folder1/catalog/ABC/10162015/Asdf.jpg -> folder1/catalog/ABC/10162015/Asdf.jpg, referer: http://site.example.com/widgets/bathroom/ [Fri Nov 11 02:21:08.389775 2016] [rewrite:trace3] [pid 25637:tid 139651102975744] mod_rewrite.c(477): [client 45.67.87.76:57196] 45.67.87.76 - - [site.example.com/sid#7f031c7731e0][rid#7f02f002b310/initial] [perdir /home/someuser/public_html/] applying pattern '.*' to uri 'folder1/catalog/ABC/10162015/Asdf.jpg', referer: http://site.example.com/widgets/bathroom/ [Fri Nov 11 02:21:08.389790 2016] [rewrite:trace5] [pid 25637:tid 139651102975744] mod_rewrite.c(477): [client 45.67.87.76:57196] 45.67.87.76 - - [site.example.com/sid#7f031c7731e0][rid#7f02f002b310/initial] setting env variable'HTTP_AUTHORIZATION' to '', referer: http://site.example.com/widgets/bathroom/ [Fri Nov 11 02:21:08.389802 2016] [rewrite:trace3] [pid 25637:tid 139651102975744] mod_rewrite.c(477): [client 45.67.87.76:57196] 45.67.87.76 - - [site.example.com/sid#7f031c7731e0][rid#7f02f002b310/initial] [perdir /home/someuser/public_html/] add path info postfix: /home/someuser/public_html/folder1/catalog/ABC -> /home/someuser/public_html/folder1/catalog/ABC/10162015/Asdf.jpg, referer: http://site.example.com/widgets/bathroom/ [Fri Nov 11 02:21:08.389812 2016] [rewrite:trace3] [pid 25637:tid 139651102975744] mod_rewrite.c(477): [client 45.67.87.76:57196] 45.67.87.76 - - [site.example.com/sid#7f031c7731e0][rid#7f02f002b310/initial] [perdir /home/someuser/public_html/] strip per-dir prefix: /home/someuser/public_html/folder1/catalog/ABC/10162015/Asdf.jpg -> folder1/catalog/ABC/10162015/Asdf.jpg, referer: http://site.example.com/widgets/bathroom/ [Fri Nov 11 02:21:08.389821 2016] [rewrite:trace3] [pid 25637:tid 139651102975744] mod_rewrite.c(477): [client 45.67.87.76:57196] 45.67.87.76 - - [site.example.com/sid#7f031c7731e0][rid#7f02f002b310/initial] [perdir /home/someuser/public_html/] applying pattern '.*' to uri 'folder1/catalog/ABC/10162015/Asdf.jpg', referer: http://site.example.com/widgets/bathroom/ [Fri Nov 11 02:21:08.389835 2016] [rewrite:trace4] [pid 25637:tid 139651102975744] mod_rewrite.c(477): [client 45.67.87.76:57196] 45.67.87.76 - - [site.example.com/sid#7f031c7731e0][rid#7f02f002b310/initial] [perdir /home/someuser/public_html/] RewriteCond: input='/folder1/catalog/ABC/10162015/Asdf.jpg' pattern='!^/(folder1|folder2)/' => not-matched, referer:http://site.example.com/widgets/bathroom/ [Fri Nov 11 02:21:08.389844 2016] [rewrite:trace1] [pid 25637:tid 139651102975744] mod_rewrite.c(477): [client 45.67.87.76:57196] 45.67.87.76 - - [site.example.com/sid#7f031c7731e0][rid#7f02f002b310/initial] [perdir /home/someuser/public_html/] pass through /home/someuser/public_html/folder1/catalog/ABC, referer: http://site.example.com/widgets/bathroom/ [Fri Nov 11 02:21:08.389922 2016] [rewrite:trace3] [pid 25637:tid 139651102975744] mod_rewrite.c(477): [client 45.67.87.76:57196] 45.67.87.76 - - [site.example.com/sid#7f031c7731e0][rid#7f02f001bae8/initial/redir#1] [perdir /home/someuser/public_html/] strip per-dir prefix: /home/someuser/public_html/404.shtml -> 404.shtml, referer: http://site.example.com/widgets/bathroom/ [Fri Nov 11 02:21:08.389945 2016] [rewrite:trace3] [pid 25637:tid 139651102975744] mod_rewrite.c(477): [client 45.67.87.76:57196] 45.67.87.76 - - [site.example.com/sid#7f031c7731e0][rid#7f02f001bae8/initial/redir#1] [perdir /home/someuser/public_html/] applying pattern '.*' to uri '404.shtml', referer: http://site.example.com/widgets/bathroom/ [Fri Nov 11 02:21:08.389958 2016] [rewrite:trace5] [pid 25637:tid 139651102975744] mod_rewrite.c(477): [client 45.67.87.76:57196] 45.67.87.76 - - [site.example.com/sid#7f031c7731e0][rid#7f02f001bae8/initial/redir#1] setting env variable 'HTTP_AUTHORIZATION' to '', referer: http://site.example.com/widgets/bathroom/ [Fri Nov 11 02:21:08.389969 2016] [rewrite:trace3] [pid 25637:tid 139651102975744] mod_rewrite.c(477): [client 45.67.87.76:57196] 45.67.87.76 - - [site.example.com/sid#7f031c7731e0][rid#7f02f001bae8/initial/redir#1] [perdir /home/someuser/public_html/] strip per-dir prefix: /home/someuser/public_html/404.shtml -> 404.shtml, referer: http://site.example.com/widgets/bathroom/ Sub final_row1() Dim i As Integer Dim notFound As Boolean For i = 2 To 10 notFound = Application.IsError(Application.VLookup(Cells(i, 2), Range("F2:G8"), 1, False)) If notFound = False Then Cells(i, 3).Value = "counterparty" Else Cells(i, 3).Value = "client" End If Next i End Sub 取决于df[each_column].reshape(-1, 1)中包含的数据的性质,如弃用警告消息所述。它会将您的1D数组转换为"列"或者"行"矢量。