简体   繁体   中英

sklearn MinMaxScaler that save rows and columns headers python

I am trying to normalize the df and saving the columns and rows index/headers.

      Sym1 Sym2 Sym3 Sym4
1     1    1    1    2
8     1    3    3    2
9     1    2    2    2
24    4    2    4    1


scaler = MinMaxScaler(feature_range=(0, 1), copy=True)
scaler.fit(df)
normData = pd.DataFrame(scaler.transform(df))

But i get countinus rows and coulmns:

      0    1    2    3
0     0    0    0    0.8
1     0    1    0.65 0.8
2     0    0.24 0.5  0.2
3     0.5  0.5  0.5  0.25

and i want a dataframe like this:

      Sym1 Sym2 Sym3 Sym4
1     0    0    0    0.8
8     0    1    0.65 0.8
9     0    0.24 0.5  0.2
24    0.5  0.5  0.5  0.25

what can I do?

转换为DataFrame时,需要指定所需的列和索引。

normData = pd.DataFrame(scaler.transform(df), index=df.index, columns=df.columns)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM