Python ufunc的循环不支持没有可调用日志方法的str类型的参数0

Python ufunc的循环不支持没有可调用日志方法的str类型的参数0,python,pandas,numpy,logarithm,Python,Pandas,Numpy,Logarithm,对于作业,我必须计算股票的对数回报率。 在我写入df_ret=100*(np.log(df)-np.log(df.shift(1))之后,我得到以下错误: AttributeError Traceback (most recent call last) AttributeError: 'str' object has no attribute 'log' The above exception was the direct cause of

对于作业,我必须计算股票的对数回报率。 在我写入
df_ret=100*(np.log(df)-np.log(df.shift(1))
之后,我得到以下错误:

AttributeError                            Traceback (most recent call last)
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-107-aa65effd67b2> in <module>()
----> 1 df_ret = 100*(np.log(df) - np.log(df.shift(1)))

TypeError: loop of ufunc does not support argument 0 of type str which has no callable log method
[enter image description here][1]
AttributeError回溯(最近一次调用)
AttributeError:“str”对象没有属性“log”
上述异常是以下异常的直接原因:
TypeError回溯(最近一次调用上次)
在()
---->1 df_ret=100*(np.log(df)-np.log(df.shift(1)))
TypeError:ufunc的循环不支持没有可调用日志方法的str类型的参数0
[在此处输入图像描述][1]

有人能帮忙吗?

数据框中有什么?df=pd.read_csv('tickerdata.csv')csv文件由不同的股票组成,它们在2010-2020年间的收盘价df包含
str
元素,不能使用a数值
np.log
函数。您确实了解
log
的功能,不是吗?你知道你的
df
包含什么吗?列是不同的股票/股票名称,行代表从2010年到2020年的日期(月度数据)。因此,数据包括每个月不同股票的收盘价