Python: Scaling numbers column by column with pandas

后端 未结 6 941
不知归路
不知归路 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:41

    I think Acumenus' comment in this answer, should be mentioned explicitly as an answer, as it is a one-liner.

    >>> import pandas as pd
    >>> from sklearn.preprocessing import minmax_scale
    >>> df = pd.DataFrame({'A':[14,90,90,96,91], 'B':[103,107,110,114,114]})
    >>> minmax_scale(df)
    array([[0.        , 0.        ],
           [0.92682927, 0.36363636],
           [0.92682927, 0.63636364],
           [1.        , 1.        ],
           [0.93902439, 1.        ]])
    

提交回复
热议问题