add seconds in float and int type to date

Viewed 83

I have a list of seconds including float and integers types. When I add the seconds in int type, my code works but in the case of float, it gives me the following error,

"TypeError: unsupported type for timedelta seconds component: Timestamp"

For example, it works for 0 and 5 but it doesn't for 3.14 seconds. Would you please have any suggestions to solve this problem?

thank you very much

Here is my code

first_day = df.iloc[1, 0][0:8] 
date = datetime.strptime(first_day, '%Y%m%d').strftime('%m/%d/%Y %H:%M:%S')
with open('myfile.txt','w') as f:
for i in range(len(df)):
    itp = df.iloc[5, 1].replace('[', '').replace(']', '')
    if itp != '':
        P=int(float(itp))/100
    else:
        P=0
        print(P)
        type(P)
    #P_sec=itp/100
        P= pd.to_datetime(date) + pd.DateOffset(seconds=30)
        t2=pd.to_datetime(date) + pd.DateOffset(seconds=P)
        date=pd.to_datetime(t1) - pd.DateOffset(seconds=15)
        print(date,P,t2,file = f)
0 Answers
Related