Let’s say that we want to apply the MinMaxScaler
from the Sklearn in a pandas Data Frame by row and not by column which is the default.
import pandas as pd from sklearn.preprocessing import MinMaxScaler #for this post we will use MinMaxScaler scaler=MinMaxScaler() df=pd.DataFrame({'A':[10,0.3,141],'B':[13,0.5,110],'C':[11,0.1,107]}) df
A B C
0 10.0 13.0 11.0
1 0.3 0.5 0.1
2 141.0 110.0 107.0
scaled=pd.DataFrame(scaler.fit_transform(df.T).T,columns=df.columns) scaled
A B C
0 0.0 1.000000 0.333333
1 0.5 1.000000 0.000000
2 1.0 0.088235 0.000000