【发布时间】:2020-10-27 02:49:54
【问题描述】:
我一直致力于根据 Min-Max Normalization 对数据进行规范化。 我的数据集是存储在 df_mols 列表中的数据帧,如下所示。
df_mols[0]:
frequency Molecule0
0 -326.0 2.604015
1 -323.0 2.624186
2 -321.0 2.644598
3 -318.0 2.665254
4 -316.0 2.686159
... ... ...
1996 4589.0 4.565467
1997 4591.0 4.512142
1998 4594.0 4.459744
1999 4596.0 4.408251
2000 4598.0 4.357645
df_mols[1]:
frequency Molecule1
0 -357.0 0.368472
1 -354.0 0.371063
2 -352.0 0.373683
3 -350.0 0.376332
4 -347.0 0.379010
... ... ...
1996 4293.0 0.538391
1997 4295.0 0.532088
1998 4297.0 0.525894
1999 4300.0 0.519807
2000 NaN NaN
我只想规范化所有 Molecule 列。 到目前为止,我所做的是,
from sklearn.preprocessing import MinMaxScaler
scaler=MinMaxScaler()
for i in df_mols:
i['frequency']=i['frequency'].apply(np.rint) # This was to make frequency values into int
i[:,1]=scaler.fit_transform(i[:,1])
并出现如下错误
/usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
554 "Reshape your data either using array.reshape(-1, 1) if "
555 "your data has a single feature or array.reshape(1, -1) "
--> 556 "if it contains a single sample.".format(array))
557
558 # in the future np.flexible dtypes will be handled like object dtypes
ValueError: Expected 2D array, got 1D array instead:
array=[2.60401472 2.62418641 2.64459837 ... 4.45974369 4.4082515 4.35764454].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
我试图重塑,但做不到。我应该制作新系列然后更新价值吗?或者我应该解决这个问题? 谢谢你:)
【问题讨论】:
标签: python pandas numpy dataframe