gpt4 book ai didi

python - 类型错误 : cannot convert the series to using pow

转载 作者:太空宇宙 更新时间:2023-11-03 20:33:24 25 4
gpt4 key购买 nike

我有数据框,我想计算每行的 10^(0.13*df['value']) 并将结果保存到新列。

df:

值|值2

<小时/>

22
12
22
33

我想在列 value2 中保存结果,例如:第一行为 10^(-0.13*22)。

我尝试过:

导入数学

df['value2'] = math.pow(10, -0.13*df['value'])

类型错误:无法将系列转换为“float”类

最佳答案

python 函数 math.pow 期望第二个参数为 float 类型,因为你想计算系列中每个元素的幂,你应该使用 numpy 包,所以可以尝试

import numpy as np
np.power(10, -13 * df['value'])

关于python - 类型错误 : cannot convert the series to <class 'float' > using pow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57333098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com