【发布时间】:2016-01-28 09:59:30
【问题描述】:
我有浮点数作为数据的数据框,我想规范化数据,所以首先我将它转换为 int(否则我有错误ValueError: Input contains NaN, infinity or a value too large for dtype('float64').)
我的规范化代码:
def normalize_df():
x = my_df.values.astype(int)
min_max_scaler = preprocessing.MinMaxScaler()
x_scaled = min_max_scaler.fit_transform(x)
df = pd.DataFrame(x_scaled)
return df
我的输出是
0 1 2 3 4 5 6 7 8 9 ... 12 13 14 15 16 17 18 19 20 21
0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
发生了什么(假设我的初始数据帧在某些行中包含值 0 但不到数据帧的 30%)?如何修复此错误并避免输出为零?
已编辑
我的数据看起来像(有更多的列和行):
36680 0 22498037 2266
0 2218 22502676 0
26141 0 22505885 4533
39009 0 22520711 4600
36237 0 22527171 5933
我试图将值从 0.0 到 1.0
【问题讨论】:
-
您能提供示例数据和预期输出吗?
标签: python pandas scikit-learn dataframe normalization