【发布时间】:2017-11-09 17:51:32
【问题描述】:
我正在尝试使用 sklearn.LinearRegression 找到大量短系列的对数斜率。数据是从 pandas 数据框的行中提取的,如下所示:
bp01 1.12
bp02 1.12
bp03 1.08
bp04 0.99
bp05 1.08
bp06 1.19
bp07 1.17
bp08 1.05
bp09 0.8
bp10 0.96
bp11 0.97
bp12 1.12
bp13 0.91
bp14 0.96
bp15 1.05
bp16 0.93
bp17 0.97
bp18 0.92
bp19 0.89
bp20 0
Name: 42029, dtype: object
但是,当我尝试使用 np.log10 时,在系列中我收到以下错误:
In[27]: test.apply(np.log10)
Traceback (most recent call last):
File "<ipython-input-27-bccff3ed525b>", line 1, in <module>
test.apply(np.log10)
File "C:\location", line 2348, in apply
return f(self)
AttributeError: 'numpy.float64' object has no attribute 'log10'
我不确定为什么会出现此错误,np.log10 应该与我所看到的 numpy.float64 一起使用。想法?
【问题讨论】:
-
试试这个:
test.apply(lambda x: np.log10(x)) -
test 是一个 pd.series。 apply 应该将系列中的每个值都传递给 np.log10 命令,对吗?
-
查看this question是否重复。
-
你调用了一个浮点变量
np。