【发布时间】:2020-11-18 05:30:34
【问题描述】:
我有一个包含多列的 pandas 数据框。我需要在每一列上使用 groupby 函数,然后使用 Keras StandardScaler 函数来转换数据框中的每一列。我尝试了以下代码:
from sklearn.preprocessing import StandardScaler
scaler=StandardScaler()
df2= df.groupby('Sector').apply(lambda x: scaler.fit_transform(x.astype(float)))
但它按组返回数据列表,但是,我需要保留数据帧的初始结构。
我特别需要使用 StandardScaler,因为之后我想用它来转换测试功能。
在这种情况下有没有办法使用 StandardScaler?
【问题讨论】:
-
请提供一些样本数据进行测试。请花点时间阅读有关如何发布熊猫问题的信息:stackoverflow.com/questions/20109391/…
标签: python python-3.x pandas keras