How can I normalize the data in a range of columns in my pandas dataframe

前端 未结 4 1269
执念已碎
执念已碎 2021-02-01 04:56

Suppose I have a pandas data frame surveyData:

I want to normalize the data in each column by performing:

surveyData_norm = (surveyData - surveyData.mean         


        
4条回答
  •  耶瑟儿~
    2021-02-01 05:22

    I think it's better to use 'sklearn.preprocessing' in this case which can give us much more scaling options. The way of doing that in your case when using StandardScaler would be:

    from sklearn.preprocessing import StandardScaler
    cols_to_norm = ['Age','Height']
    surveyData[cols_to_norm] = StandardScaler().fit_transform(surveyData[cols_to_norm])
    

提交回复
热议问题