0

I want to use two transformation techniques on a data frame, mean centering and standardization. How can I perform the mean centering method on my dataframe?

I have performed standardization using StandardScaler() from sklearn.preprocessing.

from sklearn.preprocessing import StandardScaler()

standard.iloc[:,1:-1] = StandardScaler().fit_transform(standard.iloc[:,1:-1])

I am expecting a transformed data frame which is mean-centered

Umar.H
  • 22,559
  • 7
  • 39
  • 74
  • Hey there, I don't know how to answer this question, but others that will will need to see some sample data and your expected output. please read https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples – Umar.H Sep 24 '19 at 04:53
  • What do you mean by mean centering? Any numeric variable by definition is centered on the mean already. – Franco Piccolo Sep 24 '19 at 07:19

1 Answers1

0
dataxx = {'Name':['Tom', 'gik','Tom','Tom','Terry','Jerry','Abel','Dula','Abel'], 
      'Age':[20, 21, 19, 18,88,89,95,96,97],'gg':[1, 1,1, 30, 30,30,40,40,40]} 
dfxx = pd.DataFrame(dataxx)

dfxx["meancentered"] = dfxx.Age - dfxx.Age.mean()
Index Name Age gg meancentered
0 Tom 20 1 -40.333333
1 gik 21 1 -39.333333
2 Tom 19 1 -41.333333
3 Tom 18 30 -42.333333
4 Terry 88 30 27.666667
5 Jerry 89 30 28.666667
6 Abel 95 40 34.666667
7 Dula 96 40 35.666667
8 Abel 97 40 36.666667
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103