I have the following dataframe df
;
Name Date Attr1 Attr2 Attr3
0 Joe 26-12-2007 53.45 53.4500 52.7200
1 Joe 27-12-2007 52.38 52.7399 51.0200
2 Joe 28-12-2007 51.71 51.8500 50.7300
I would like to scale the floating values in columns Attr1
, Attr2
, Attr3
to between 0 and 1. The highest value in a column is scaled to 1. Please note that not all the columns are to be scaled.
I am using Python 3.6.
The following code will scale all the columns but I need to scale selected columns. Another problem is that some columns are in date and string form. The code below will encounter problems converting the values to floating.
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
scaled_values = scaler.fit_transform(df)
df.loc[:,:] = scaled_values