gpt4 book ai didi

python - ufunc 的到期循环错误不支持没有可调用日志方法的 str 类型的参数 0

转载 作者:行者123 更新时间:2023-12-05 02:04:11 25 4
gpt4 key购买 nike

当我使用下面的日志功能时,我在我的 jupyter notebook 中收到以下错误消息。data1 = np.log(mdata).diff().dropna()我试图做 Actor 但无法摆脱这个问题。---------------------------------------------- --------------------------AttributeError Traceback(最后一次调用)AttributeError: 'str' 对象没有属性 'log'

The above exception was the direct cause of the following exception:

TypeError Traceback (most recent call last)
<ipython-input-13-b6f1878a7619> in <module>
----> 1 data1 = np.log(mdata).diff().dropna()

TypeError: loop of ufunc does not support argument 0 of type str which has no callable log method

数据:

          Field1    Field2  Field3  Field4
TS
2020-11-02 00:43:58.500 1595000 849332 205 69
2020-11-02 00:43:58.500 1408000 820332 198 51
2020-11-02 00:43:58.500 1770000 926054 213 56
2020-11-02 00:43:58.500 1760000 1002332 216 72
2020-11-02 00:43:58.500 1850000 957054 213 59
... ... ... ... ...

数据索引:

DatetimeIndex(['2020-11-02 00:43:58.500000', '2020-11-02 00:43:58.500000',
'2020-11-02 00:43:58.500000', '2020-11-02 00:43:58.500000',
'2020-11-02 00:43:58.500000', '2020-11-02 00:43:58.500000',
'2020-11-02 00:43:58.500000', '2020-11-02 00:43:58.500000',
'2020-11-02 00:43:58.600000', '2020-11-02 00:43:58.600000',
...

'2020-11-02 00:44:00.400000', '2020-11-02 00:44:00.500000'],
dtype='datetime64[ns]', name='TS', length=199, freq=None)

完整代码为

df1 = pd.read_csv('inputdata.csv')
cols = ['Field1','Field2','Field3','Field4']
data_x = pd.to_datetime(data_x)
mdata = df1[cols]
mdata.index = pd.DatetimeIndex(data_x)
data1 = np.log(mdata).diff().dropna()

The following statements are not executed due to the issue in the above statement

model = VAR(data)
results = model.fit(2)
results.summary()

最佳答案

问题是您的数据列不是数字类型,numpy.log() 需要数字数据。您可以使用 pandas.to_numeric()

将数据转换为数值
mdata = df1[cols].apply(pd.to_numeric)

或使用 DataFrame.astype()

将列转换为特定的数字类型
mdata = df1[cols].astype(float)

关于python - ufunc 的到期循环错误不支持没有可调用日志方法的 str 类型的参数 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64636018/

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