unsupported operand type(s) for +: 'float' and 'datetime.timedelta'", 'occurred at index 5')

前端 未结 1 1846
梦毁少年i
梦毁少年i 2021-01-29 03:25

I have a dataset with one input with date and time . First I wrote the code to find the first time of 5 value in X3 column and I turn that time into 0. Then I tried to add timed

相关标签:
1条回答
  • 2021-01-29 03:59

    In your code time= data['duration'].eq(0) this part is making the time variable of bool type. Try to convert it to 0 or 1 then add it in for loop.

    If time is scalar (single) value :

    if (time==True):
        time=1
    else:
        time=0
    

    if time is vector (array) :

    time_array = [0 if tm==False else 1 for tm in data['duration'].eq(0)]
    

    Also, there is one more mistake in your for loop. You can't add 1 like this to data time. Try this :

    from datetime import datetime, timedelta
    current_time = datetime.now()
    nine_hours_from_now = current_time  + timedelta(hours=9)
    

    In this code you can replace timedelta(hours=9) by your time timedelta(hours = time).

    Note : your time will be a binary array. you have to reaverse is to pick the values and add.

    0 讨论(0)
提交回复
热议问题