【问题标题】:How to do mean centering on a dataframe in pandas?如何以熊猫的数据框为中心?
【发布时间】:2020-01-24 03:44:33
【问题描述】:

我想在数据框上使用两种转换技术,均值居中和标准化。如何在我的数据框上执行平均居中方法?

我已经使用StandardScaler() from sklearn.preprocessing. 进行了标准化

from sklearn.preprocessing import StandardScaler()

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

我期待一个以均值为中心的转换数据框

【问题讨论】:

  • 您好,我不知道如何回答这个问题,但其他人需要查看一些示例数据和您的预期输出。请阅读stackoverflow.com/questions/20109391/…
  • 居中是什么意思?根据定义,任何数值变量都已经以均值为中心。

标签: python-3.x pandas jupyter-notebook


【解决方案1】:
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

【讨论】:

    猜你喜欢
    • 2018-02-28
    • 2019-02-15
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 2021-06-02
    • 1970-01-01
    • 2015-06-11
    相关资源
    最近更新 更多