简体   繁体   English

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

[英]Error in due loop of ufunc does not support argument 0 of type str which has no callable log method

When I use the below log function, i am getting the following error message in my jupyter notebook.当我使用以下日志功能时,我在 jupyter 笔记本中收到以下错误消息。 data1 = np.log(mdata).diff().dropna() I tried to do cast but unable to get rid of this issue. data1 = np.log(mdata).diff().dropna() 我试图做演员但无法摆脱这个问题。 --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) AttributeError: 'str' object has no attribute 'log' -------------------------------------------------- ------------------------- AttributeError Traceback(最近一次调用最后一次) AttributeError: 'str' object has no attribute '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

mdata:数据:

          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
... ... ... ... ...
 

mdata.index: mdata.index:

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)

Complete code is完整的代码是

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()

The problem is that your data columns aren't a numeric type, and numpy.log() expects numeric data.问题是您的数据列不是数字类型,并且numpy.log()需要数字数据。 You can convert the data to numeric values using pandas.to_numeric()您可以使用pandas.to_numeric()将数据转换为数值

mdata = df1[cols].apply(pd.to_numeric)

or by converting the columns to a specific numeric type by using DataFrame.astype()或者通过使用DataFrame.astype()将列转换为特定的数字类型

mdata = df1[cols].astype(float)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError: ufunc 的循环不支持没有可调用日志方法的 ArrayBox 类型的参数 0 - TypeError: loop of ufunc does not support argument 0 of type ArrayBox which has no callable log method ufunc 的循环不支持浮点类型的参数 0,它没有可调用的 exp 方法 - loop of ufunc does not support argument 0 of type float which has no callable exp method TypeError: ufunc 的循环不支持 Symbol 类型的参数 0,它没有可调用的 sqrt 方法 - TypeError: loop of ufunc does not support argument 0 of type Symbol which has no callable sqrt method 类型错误:ufunc 的循环不支持没有可调用 sin 方法的 Add 类型的参数 0 - TypeError: loop of ufunc does not support argument 0 of type Add which has no callable sin method TypeError:ufunc 的循环不支持浮点类型的参数 0,它没有可调用的 exp 方法 - TypeError: loop of ufunc does not support argument 0 of type float which has no callable exp method python3 np.exp(matrix1 * matrix2)中的错误-“ufunc循环不支持float类型的参数0,它没有可调用的exp方法” - Error in python3 np.exp(matrix1 * matrix2) - “loop of ufunc does not support argument 0 of type float which has no callable exp method” 为什么我会收到日志方法的“ufunc 循环不支持 numpy.ndarray 类型的参数 0”错误? - Why do I get the 'loop of ufunc does not support argument 0 of type numpy.ndarray' error for log method? “ufunc循环不支持Mul类型的参数0”是什么意思? - What does "loop of ufunc does not support argument 0 of type Mul" mean? 为什么我会收到 numpy.exp 的“ufunc 循环不支持 int 类型的参数 0”错误? - Why do I get the 'loop of ufunc does not support argument 0 of type int' error for numpy.exp? nplog“TypeError:ufunc循环不支持int类型的参数0”后的PYTHON错误 - PYTHON Error after nplog "TypeError: loop of ufunc does not support argument 0 of type int "
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM