【问题标题】:ufunc 'boxcox1p' not supported for the input types. the inputs could not be safely coerced to any supported types according to the casting rule 'safe'输入类型不支持 ufunc \'boxcox1p\'。根据强制转换规则“安全”,输入无法安全地强制转换为任何支持的类型
【发布时间】:2022-08-20 10:47:29
【问题描述】:

我在下面有这个代码(用于机器学习):

from scipy.special import boxcox1p
from scipy.special import boxcox
from scipy.special import inv_boxcox
df_trans=df1.apply(lambda x: boxcox1p(x,0.0))

df1 是一个包含日期和一些其他值的数据框

但是,运行上述代码后,我得到了这个错误:

TypeError                                 Traceback (most recent call last)
Input In [585], in <cell line: 4>()
      2 from scipy.special import boxcox
      3 from scipy.special import inv_boxcox
----> 4 df_trans=df1.apply(lambda x: boxcox1p(x,0.0))

TypeError: ufunc \'boxcox1p\' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule \'\'safe\'\'

我该如何解决?

编辑:这是代码示例的一部分:

    Quantity   Price        Difference  Money Received
0   55419      12.908304    8.518790    69665.133754
1   45179      28.492719    8.518790    125359.752289
2   11985      17.040535    18.776097   19888.813469
  • 请以文本格式包含您的数据框示例。通过这种方式,人们实际上将能够使用这些数据来尝试重现您的问题。你可以edit这个问题。
  • 哦,好的,我添加了一部分
  • 在此数据样本上运行您的代码不会产生错误。你提到你也有一个日期列?如果将日期列(datetime 类型)添加到您的示例中,则会出现这个确切的错误。您可能不打算对日期值执行转换,因此排除该列。
  • 哦,现在可以了,TYSM Alex

标签: python pandas scipy


【解决方案1】:

答案是排除日期列。特别感谢@AlexK 的帮助!

【讨论】:

    猜你喜欢
    • 2019-12-04
    • 2019-03-10
    • 1970-01-01
    • 2021-12-01
    • 1970-01-01
    • 2020-07-21
    • 2020-09-29
    • 2023-03-30
    • 1970-01-01
    相关资源
    最近更新 更多