【问题标题】:TypeError: Addition/subtraction of integers and integer-arrays with Timestamp is no longer supportedTypeError:不再支持带时间戳的整数和整数数组的加法/减法
【发布时间】: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`

【问题讨论】:

    标签: python pandas


    【解决方案1】:

    那么这是不可能的,因为你直接在时间戳 list_of_volumen.append(data['Volume'][swieca-k]) 上进行操作

    【讨论】:

    • 所以我必须先在这个数据框中添加索引列或者可以用其他方式吗?
    • 是的,你当然可以添加除日期时间以外的任何类型的索引,或者你可以使用 to_ordinal() 转换你的时间戳,但更好的方法是默认使用索引作为数字,然后尝试分析
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多