【发布时间】:2021-11-12 22:20:56
【问题描述】:
某些列的数据不服从正态分布,我想通过对数变换对其进行归一化。
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(14,6))
#1
sns.distplot(train_df['MasVnrArea'], fit=stats.norm, ax=ax[0])
ax[0].set_title('Before Normalization')
#2
train_df['MasVnrArea'] = np.log(train_df['MasVnrArea'])
ax[1].set_title('After Normalization')
sns.distplot(train_df['MasVnrArea'], fit=stats.norm, ax=ax[1])
#1 部分工作正常,但是当涉及#2 部分时,它给了我这个错误:
ValueError: cannot convert float NaN to integer
我已经检查了此列中是否有 NaN 值,但什么也没有。那么它有什么问题呢?
【问题讨论】:
-
难以调试,因为我们无权访问您的数据。你能发布一个有代表性的数据集吗?否则很难提供帮助。
-
Kaggle 的数据集之一。 house price
标签: python pandas normalization valueerror normal-distribution