Python: Scaling numbers column by column with pandas

后端 未结 6 942
不知归路
不知归路 2020-12-13 08:54

I have a Pandas data frame \'df\' in which I\'d like to perform some scalings column by column.

  • In column \'a\', I need the maximum number to be 1, the minimum
6条回答
  •  长情又很酷
    2020-12-13 09:52

    In case you want to scale only one column in the dataframe, you can do the following:

    from sklearn.preprocessing import MinMaxScaler
    
    scaler = MinMaxScaler()
    df['Col1_scaled'] = scaler.fit_transform(df['Col1'].values.reshape(-1,1))
    

提交回复
热议问题