【发布时间】:2016-11-20 02:58:48
【问题描述】:
我想使用sklearn 的StandardScaler。是否可以将其应用于某些特征列但不能应用于其他列?
例如,假设我的data 是:
data = pd.DataFrame({'Name' : [3, 4,6], 'Age' : [18, 92,98], 'Weight' : [68, 59,49]})
Age Name Weight
0 18 3 68
1 92 4 59
2 98 6 49
col_names = ['Name', 'Age', 'Weight']
features = data[col_names]
我适应并改造了data
scaler = StandardScaler().fit(features.values)
features = scaler.transform(features.values)
scaled_features = pd.DataFrame(features, columns = col_names)
Name Age Weight
0 -1.069045 -1.411004 1.202703
1 -0.267261 0.623041 0.042954
2 1.336306 0.787964 -1.245657
当然,名称不是真正的整数而是字符串,我不想将它们标准化。如何仅在 Age 和 Weight 列上应用 fit 和 transform 方法?
【问题讨论】:
标签: python pandas scikit-learn scale data-science