【发布时间】:2021-10-15 18:56:23
【问题描述】:
我有以下代码来测试一只股票是否创造了新的生命周期新高。 Bool 输出应该使用 numpy 比较生成。
import pandas as pd
from pandas_datareader import data as web
import numpy as np
import math
data = web.DataReader('goog', 'yahoo')
data['lifetime'] = data['High'].asfreq('D').rolling(window=999999, min_periods=1).max() #To check if it is a lifetime high
data['lifetime'] = data['lifetime'].astype(float)
data['isclose'] = np.where(math.isclose(data['High'], data['lifetime'], rel_tol = 0.003), 1, 0)
iterating over each row in pandas to evaluate condition 此处提供的此解决方案应该可以工作,但我收到此错误。
TypeError: 无法将系列转换为
我看了一些,似乎math 函数需要一个值而不是数组。我怎样才能验证它是这种情况? TypeError: cannot convert the series to <class 'float'>
【问题讨论】: