将2个熊猫系列划分为十进制值(每日股价)时出错

时间:2017-06-12 12:54:43

标签: pandas unsupportedoperation

我试图划分2个pandas列(相同的列除以移动一个单元格),但得到如下错误...

..这是令人惊讶的,因为我在按时间序列数据之前多次进行过这样的计算,并且从未遇到过这个问题。

有人可以建议这里发生了什么吗?...我正在计算一个股票的Adj Close价格的每日回报,所以需要十进制答案。

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

我认为您需要转换为float第一列,因为dtypeobject,显然是string

z = x.astype(float) / y.astype(float)

或者:

data['Adj Close'] = data['Adj Close'].astype(float)
z = data['Adj Close'].shift(-1) / data['Adj Close']