import pandas
from pandas import read_excel
from sklearn.preprocessing import MinMaxScaler
dataset = read_excel('G:\文件夹1\文件夹2\文件夹3\data.xls', header=0, index_col=0)
values = dataset.values # 将dataframe转化为array
values = values.astype('float32') # 定义数据类型
# 标准化
tool = MinMaxScaler(feature_range=(0, 1))
data = tool.fit_transform(values)
df = pandas.DataFrame(data) # 将array转化为dataframe
df.columns = dataset.columns # 命名标题行
df.to_excel('G:\文件夹1\文件夹2\文件夹3\data2.xls', index=None) # 另存为excel(删除索引)
原始数据:
最大最小标准化后的数据:
相关链接
1、Decimal scaling标准化计算的python代码
2、最大最小标准化计算的python代码