python – 使用StandardScaler()规范化pandas数据框,不包括特定列

所以我有一个数据框,我通过合并训练(标记)和测试(未标记)数据帧形成.并且为了取消附加测试数据框,我保留了一个列,如果该行属于训练或测试,则该列具有标识符.
现在我必须规范化所有列中的所有值,除了这一列“Sl No.”但我没有找到任何方法通过这一栏.
这就是我在做的事情

import pandas as pd
import numpy as np
from sklearn.preprocessing import StandardScaler

data_norm = data_x_filled.copy() #Has training + test data frames combined to form single data frame
normalizer = StandardScaler()
data_array = normalizer.fit_transform(data_norm)
data_norm = pd.DataFrame(data_array,columns = data_norm.columns).set_index(data_norm.index)

我只想排除“Sl No.”栏目规范化但希望在规范化后保留它.

解决方法:

尝试这可能工作使用numpy作为np:

data_norm = data_x_filled.copy() #Has training + test data frames combined to form single data frame
normalizer = StandardScaler()
data_array = normalizer.fit_transform(data_norm.ix[:,data_norm.columns!='SI No'])
data_norm = pd.DataFrame(np.column_stack((data_norm['SI No'].values,data_array)),columns = data_norm.columns).set_index(data_norm.index)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐