I am learning a bit about Standard Scaler in datasets. I am noticing a strange behavior which I think might be a syntax or logical error in my code, but can anyone correct me.
As we know that when we do StandardScaler, we have a std of 1 and mean of 0 as Var = Stdev^2.
Now when I used this in my code with sklearn.preprocessing.StandardScaler, after using fit_transform, the variance was 1. But when I changed the value in original data frame, It was 1.5 for both rows. Can I know why is it and how to make it 1 using StandardScaler. Thanks.
Here is my dataset
Country GDP Area Continent
0 India 2.79 3.287 Asia
1 USA 20.54 9.840 North America
2 China 13.61 9.590 Asia
and here is my code
from sklearn.preprocessing import StandardScaler
ss = StandardScaler()
var = ss.fit_transform(catDf.iloc[:,1:-1]).var() #This variance is equal to 1
catDf.iloc[:,1:-1] = ss.fit_transform(catDf.iloc[:,1:-1])
print("Variance in Numpy array", var) # Approx 1
print("Variance in Data Frame", catDf.var())# 1.5 for both numerical columns
Hopefully, you got what I want to say.