sum = data.isna().sum()
data = data.drop(columns=sum.index[sum.argmax()])
当使用Pandas2.*版本的时候,将无法通过inputs.mean()直接进行填充。需要选中相应的列,计算均值,然后相应处理。 其次,在Pandas2.*版本下,pd.get_dummies()返回值将是True与False的形式,但与1, 0是通用的。
如果遇到inputs = inputs.fillna(inputs.mean())报错:TypeError: can only concatenate str (not “int”) to str
可以采用:inputs = inputs.fillna(inputs.select_dtypes(include=‘number’).mean())
解决问题
you can also use the Pandas version 1.5.0 to solve this problem(TypeError: can only concatenate str (not “int”) to str)
如果遇到 [AttributeError: module ‘numpy’ has no attribute ‘bool’?]
在版本 NumPy 1.24.0 中,已弃用的 np.bool
被完全删除。这意味着您使用的 NumPy 版本删除了已弃用的方法,并且您使用的库未更新以匹配该版本(使用类似 np.bool
而不是 < a i=5>).bool
您可以使用旧版本的numpy
(删除之前),但该问题尚未修复。 最新的是 1.23.5。
#pip install numpy==1.23.5
In pandas 2.x, if you encounter issues with str and int types,just tweak the line
inputs = inputs.fillna(inputs.mean())
to
inputs = inputs.fillna(inputs.mean(numeric_only=True))