AttributeError: 'Series' object has no attribute 'applymap' while applying logTransformation

AttributeError: 'Series' object has no attribute 'applymap' while applying logTransformation

使用 Python 对包含 <0、>0 等值的列进行日志转换时出错。 这是正确的方法吗..? df["A3"].applymap(lambda x: np.log(x+1) 如果 x>0 否则 -np.log(-x+1) ).hist() plt.show()

Applymap 是一个数据框级别的函数,您正试图将它应用于单个列(这是一个系列),这就是它抛出此错误的原因

查看原始文档here

相反,您可以使用 'apply' 函数,该函数适用于所述系列 enter link description here