欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

AttributeError: 'Series' object has no attribute 'reshape'

程序员文章站 2022-03-26 23:21:05
...

AttributeError: ‘Series’ object has no attribute ‘reshape’

错误代码:

from sklearn.preprocessing import StandardScaler
data['normAmount'] = StandardScaler().fit_transform(data['Amount'].reshape(-1, 1))

解决方法:

用values方法将Series对象转化成numpy的ndarray,再用ndarray的reshape方法。

from sklearn.preprocessing import StandardScaler
data['normAmount'] = StandardScaler().fit_transform(data['Amount'].values.reshape(-1, 1))