【发布时间】:2021-01-08 04:55:38
【问题描述】:
我遇到了熊猫问题,尤其是在按索引号移动数据帧时。
这是我的代码:
def wolumen(data, swieca):
list_of_volumen = []
for k in range(1, 30):
list_of_volumen.append(data['Volume'][swieca-k])
print(list_of_volumen)
candle = 0
hammer = 0
for i in data_frame.index:
candle+=1
if data_frame["Close"][i] < data_frame["Open"][i]:
body = 3 * (data_frame["Open"][i] - data_frame["Close"][i])
down_shadow = data_frame["Close"][i] - data_frame["Low"][i]
if body < down_shadow:
up_shadow = data_frame["High"][i] - data_frame["Open"][i]
if body > up_shadow:
hammer+=1
print("Hammer!!!")
print(data_frame.loc[i])
wolumen(data_frame, i)
我想用 pandas 和 yfinance 分析一些股票数据,我的 data_frame 是这样的:
| Open High Low Close Adj Close Volume
Datetime |
2020-01-10 09:00:00+01:00 | 9.950 10.075 9.900 10.030 10.030 767203
我无法将行的体积添加到这个 lis_of_volumen
完整的错误如下所示:
Traceback (most recent call last):
File "aaa.py", line 45, in <module>
wolumen(data_frame, i)
File "aaa.py", line 28, in wolumen
list_of_volumen.append(data['Volume'][swieca-k])
File "pandas\_libs\tslibs\timestamps.pyx", line 343, in pandas._libs.tslibs.timestamps._Timestamp.__sub__
File "pandas\_libs\tslibs\timestamps.pyx", line 320, in pandas._libs.tslibs.timestamps._Timestamp.__add__
TypeError: Addition/subtraction of integers and integer-arrays with Timestamp is no longer supported. Instead of adding/subtracting `n`, use `n * obj.freq`
【问题讨论】: