Python: Scaling numbers column by column with pandas

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

    given a data frame

    df = pd.DataFrame({'A':[14,90,90,96,91], 'B':[103,107,110,114,114]})
    

    scale with mean 0 and var 1

    df.apply(lambda x: (x - np.mean(x)) / np.std(x), axis=0)
    

    scale with range between 0 and 1

    df.apply(lambda x: x / np.max(x), axis=0)
    

提交回复
热议问题